Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR TYPESCRIPT

list remove duplicates Java

// remove duplicates with HashSet
Set<Song> songSet = new HashSet<>(songList);
System.out.println("6: " + songSet);

// TreeSet, remove duplicates and keep it sorted
Set<Song> songTreeSet = new TreeSet<>(songList);
System.out.println("7: " + songTreeSet);
// TreeSet can accept Comparator, pass it in its constructor
Set<Song> songTreeSetComparator = new TreeSet<>((o1, o2) -> o1.getBpm() - o2.getBpm());
songTreeSetComparator.addAll(songList);
System.out.println("8: (sort by BPM)" + songTreeSetComparator);
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #list #remove #duplicates #Java
ADD COMMENT
Topic
Name
7+4 =