Powered by Ajaxy
Digg StumbleUpon LinkedIn YouTube Flickr Facebook Twitter RSS Reset

Java: How to remove duplicate items from an ArrayList

Java: How to remove duplicate items from an ArrayList
{filelink=4839}

import java.util.ArrayList;
import java.util.Set;
import java.util.List;
import java.util.HashSet;
public class Doublon
{
  public static void main(String[] argv)
  	{
     List array_L = new ArrayList();
    // Add items with duplicate
    array_L.add("London");
    array_L.add("Paris");
    array_L.add("New York");
    array_L.add("London");
    array_L.add("Paris");
    array_L.add("London");
    System.out.println ("LinkedList contains(with duplicate): "+array_L);
    // remove the duplicates
    Set mySet = new HashSet(array_L);
    List array_L2 = new ArrayList(mySet);
    System.out.println("LinkedList contains(without duplicate): "+array_L2);
  }
}

Users who found this page were searching for:

  • remove duplicate list items java
  • how to use scanner in java
  • python for count

No comments yet.

Leave a Comment