Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in Java by (4k 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 (46k 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);



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!

28.4k questions

29.7k answers


94.1k users

Browse Categories