0 votes
1 view
in Java by (3.2k points)
I have an ArrayList<String>, and I want to remove repeated strings from it. How can I do this?

1 Answer

0 votes
by (39.2k points)

 Don't consider  Collection that allows duplicates. The easiest method to eliminate duplicated elements is to attach the contents to a Set (which will not allow duplicates) and then add the Set back to the ArrayList:

Set<String> set = new HashSet<>(yourList);

yourList.clear();

yourList.addAll(set);

this will end the ordering of the elements in the ArrayList. 

Hope this Helps. Cheers..!!

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...