@@ -0,0 +1,2099 @@
+package snippet;%0A%0Aimport java.util.*;%0A%0A/**%0A * Created by Administrator on 2017/10/1.%0A */%0Apublic class RemoveDuplicates %7B%0A    public static void main(String args%5B%5D)%7B%0A        byHashSet();%0A%0A        byLinkedHashSet();%0A    %7D%0A%0A    public static void byHashSet()%7B%0A        //ArrayList with duplicates String%0A        List%3CString%3E duplicateList = (List%3CString%3E) Arrays.asList(%22Android%22 , %22Android%22, %22iOS%22, %22Windows mobile%22);%0A        System.out.println(%22size of Arraylist with duplicates: %22 + duplicateList.size()); //should print 4 becaues of duplicates Android%0A%0A        System.out.println(duplicateList);%0A%0A        //Converting ArrayList to HashSet to remove duplicates%0A        HashSet%3CString%3E listToSet = new HashSet%3CString%3E(duplicateList);%0A%0A        //Creating Arraylist without duplicate values%0A        List%3CString%3E listWithoutDuplicates = new ArrayList%3CString%3E(listToSet);%0A        System.out.println(%22size of ArrayList without duplicates: %22 + listToSet.size()); //should print 3 becaues of duplicates Android removed%0A%0A        System.out.println(listWithoutDuplicates);%0A    %7D%0A%0A    /**%0A     * keep the insertion order of elements%0A     */%0A    public static void byLinkedHashSet()%7B%0A        //ArrayList with duplicates String%0A        List%3CString%3E duplicateList = (List%3CString%3E) Arrays.asList(%22Android%22 , %22Android%22, %22iOS%22, %22Windows mobile%22);%0A        //should print 4 becaues of duplicates Android%0A        System.out.println(%22size of Arraylist with duplicates: %22 + duplicateList.size());%0A        System.out.println(%22ArrayList with duplicates: %22 + duplicateList);%0A%0A        //Converting ArrayList to HashSet to remove duplicates%0A        LinkedHashSet%3CString%3E listToSet = new LinkedHashSet%3CString%3E(duplicateList);%0A%0A        //Creating Arraylist without duplicate values%0A        List%3CString%3E listWithoutDuplicates = new ArrayList%3CString%3E(listToSet);%0A        //should print 3 becaues of duplicates Android removed%0A        System.out.println(%22size of ArrayList without duplicates: %22 + listToSet.size());%0A        System.out.println(%22ArrayList after removing duplicates in same order: %22 + listWithoutDuplicates);%0A    %7D%0A%7D%0A%0A

remove duplicates, 9937