0

How to make arraylist only access original values not duplicates

To Make arraylist like as. HashSet?? code is needed

18th Dec 2017, 11:02 AM
Mohan
Mohan - avatar
1 Answer
+ 1
The easiest way to remove repeated elements is to add the contents to a Set (which will not allow duplicates) and then add the Set back to the ArrayList: List<String> al = new ArrayList<>(); Set<String> hs = new HashSet<>(); hs.addAll(al); al.clear(); al.addAll(hs);
19th Dec 2017, 1:30 PM
Hamidreza
Hamidreza - avatar