how to remove duplicates from ArrayList
in
Programming Questions
•
3 years ago
hi to all,
i'm new with processing, and i have a proble. i have an arraylist of strings, and i must remove duplicates values
In short, if i have
[1,2,1,1,2,4,2]
i want
[1,2,4].
I've tried this:
- for(int i=0; i<allNames.size(); i++) {
- for(int j=i+1; j<allNames.size(); j++) {
- if(allNames.get(i)==allNames.get(j)) {
- allNames.remove(j);
- j--;
- }
- }
- }
i really don't understand where is my mistake.
I also checked here (
http://download.oracle.com/docs/cd/E17476_01/javase/1.4.2/docs/api/java/util/List.html) but i don't find a solution.
1