How to make arraylist only access original values not duplicates | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
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 Resposta
+ 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