I have an ArrayList
, and I want to remove repeated strings from it. How can I do this?
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 s = new LinkedHashSet<>(list);
Then, if you need to get back a List
reference, you can use again the conversion constructor.