ArrayList does not have a well-packaged deduplication method, for example, for a ArrayList of [2, 5, 2, 3, 2, 4], I want to remove the duplicate elements,
I do not want to put the statement also so long, do not want to use for the method of the loop to heavy, then you can consider the ArrayList into a temporary hashset, and then the temporary HashSet converted back to ArrayList,
Because the elements inside the hashset are not repeatable! As for what is ArrayList and HashSet, in "Java" Java Collections Class--java in the upgraded version of the data structure (click to open the link) has been made clear, here no longer repeat.
You can write this:
hashset<integer> hashset_temp = new hashset<integer> (arraylist); ArrayList = new Arraylist<integer > (hashset_temp);
can also be written more concise, even the temporary hashset_temp variables are not:
ArrayList = new arraylist<integer> (new Hashset<integer> (ArrayList));
After that, the elements of ArrayList become [2, 3, 4, 5]
"Java" for ArrayList to go heavy