importjava.util.ArrayList;importjava.util.LinkedHashSet;importjava.util.List;importjava.util.Set;publicclassArrayDuplicate{publicstaticvoidmain(String args[]){List<Integer> num =newArrayList<Integer>();
num.add(1);
num.add(2);
num.add(3);
num.add(4);
num.add(5);
num.add(6);
num.add(3);
num.add(4);
num.add(5);
num.add(6);System.out.println("Your list of elements in ArrayList : "+ num);Set<Integer> primesWithoutDuplicates =newLinkedHashSet<Integer>(num);
num.clear();
num.addAll(primesWithoutDuplicates);System.out.println("list of original numbers without duplication: "+ num);}}
// remove duplicates with HashSetSet<Song> songSet =newHashSet<>(songList);System.out.println("6: "+ songSet);// TreeSet, remove duplicates and keep it sortedSet<Song> songTreeSet =newTreeSet<>(songList);System.out.println("7: "+ songTreeSet);// TreeSet can accept Comparator, pass it in its constructorSet<Song> songTreeSetComparator =newTreeSet<>((o1, o2)-> o1.getBpm()- o2.getBpm());
songTreeSetComparator.addAll(songList);System.out.println("8: (sort by BPM)"+ songTreeSetComparator);