userimage

How do I remove repeated elements from ArrayList?

There is an ArrayList of Strings, and I want to remove repeated strings from it. How can I do this?
userimage

Although converting the ArrayList to a HashSet effectively removes duplicates, if you need to preserve insertion order, I'd rather suggest you to use this variant

// list is some List of Strings

Set<String> s = new LinkedHashSet<>(list);

Then, if you need to get back a List reference, you can use again the conversion constructor.


Answer is