java 8 list eliminate duplicates code example
Example 1: java remove duplicates
import java.util.*;
public class RemoveDuplicatesFromArrayList {
public static void main(String[] args) {
List numbers = Arrays.asList(1,2,2,2,3,5);
System.out.println(numbers);
Set hashSet = new LinkedHashSet(numbers);
ArrayList removedDuplicates = new ArrayList(hashSet);
System.out.println(removedDuplicates);
}
}
Example 2: compare two lists and remove duplicates java
listA.removeAll(new HashSet(listB));