--
This code example shows how to convert ArrayList to HashSet:
This code example shows how to convert ArrayList to HashSet:
import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; public class ArrayListToHashSet { public static void main(String[] args) { ListThe above code example also can be used to remove duplicate items from an ArrayList.list = new ArrayList (); list.add(null); list.add("A"); list.add("B"); Set hashset = new HashSet (list); list = new ArrayList (hashset); System.out.println(list.toString()); } }
import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; public class ArrayListToHashSet { public static void main(String[] args) { List list = new ArrayList(); list.add(null); list.add("A"); list.add("A"); list.add("A"); list.add("A"); list.add("B"); list.add("B"); list.add("B"); list.add("C"); Set hashset = new HashSet(list); list = new ArrayList(hashset); System.out.println(list.toString()); } }
Comments
Post a Comment