java no duplicate List code example
Example 1: remove duplicates from list java
ArrayList<Object> withDuplicateValues;
HashSet<Object> withUniqueValue = new HashSet<>(withDuplicateValues);
withDuplicateValues.clear();
withDuplicateValues.addAll(withUniqueValue);
Example 2: compare two lists and remove duplicates java
listA.removeAll(new HashSet(listB));
Example 3: remove duplicates from list java
Set<String> set = new HashSet<>(yourList);
yourList.clear();
yourList.addAll(set);