I have a two dimensional ArrayList that I need to filter the duplicates out of.
current result of generateRows: [[“one”], [“two”], [“three”], [“one”]]
Java Pseudo Code:
ArrayList<ArrayList<String>> rows = new ArrayList<ArrayList<String>>();
rows = generateRows(); //method not shown, but returns a ArrayList<ArrayList<String>>
Set<String> set = new LinkedHashSet<String>();
for (ArrayList<String> list:rows) {
set.addAll (list);
}
rows.clear();
rows.add(new ArrayList<String>(set));
current result after running above conversion code: [[one, two, three]]
desired result: [[“one”], [“two”], [“three”]]
Keeping code in same lines as what you have posted, here is what you have to do.
Main issue with your routine:
Set<String> set = new LinkedHashSet<String>();you are saying set is going to contain String types while your real set of objects to be unique is of ArrayList type