I have an ArrayList
, and I want to remove repeated strings from it. How can I do this?
Code:
List duplicatList = new ArrayList();
duplicatList = Arrays.asList("AA","BB","CC","DD","DD","EE","AA","FF");
//above AA and DD are duplicate
Set uniqueList = new HashSet(duplicatList);
duplicatList = new ArrayList(uniqueList); //let GC will doing free memory
System.out.println("Removed Duplicate : "+duplicatList);
Note: Definitely, there will be memory overhead.