You can convert to Set with:
Set<String> aSet = new HashSet<String>(list);
Or you can convert to a set and return to the list with:
list = new ArrayList<String>(new HashSet<String>(list));
However, both of these parameters cannot preserve the order of the elements. To maintain order, you can use HashSetas an auxiliary structure when repeating:
List<String> list2 = new ArrayList<String>();
HashSet<String> lookup = new HashSet<String>();
for (String item : list) {
if (lookup.add(item)) {
list2.add(item);
}
}
list = list2;
. , . , , , .