public void removeDuplicates (ArrayList<ArrayList<String>> strings) {
Set<ArrayList<String>> s = new LinkedHashSet<ArrayList<String>>(strings);
strings = new ArrayList<ArrayList<String>>(s);
}
i want to remove duplicated lines in ArrayList<ArrayList<String>>, I want to use LinkedHashSet and compare ArrayList between themselves and if is the same not insert it. i know i need Comparator but i do not know how to implement it for comparing ArrayList inside ArrayList.
Thx
You could try using a Set< List > – and if you implement your own List or extend ArrayList os that the “equals()” acts the way you expect.
So when you add an arrayList it will automatically be compared with the rest.
Not sure what will happen when you add the arrayLists first and then populate them with elements.
What is your case?
You said you want to use LinkedHashSet – ok, that is the same as my initial suggestion.
(you don’t need comparator)
You can extend ArrayList and make its “equals()” method conform your wish: