Java basics: 16th days: Remove duplicate content from the collection, java 16th days
Taking the string stored in the ArrayList as an example, I did it myself before the instructor explained it in the video. The requirements are as follows:
My own practice is: traverse the set through the for loop to get the elements in the set. All the elements after the current index are the same. If they are the same, they are removed. However, after the code is complete, the implemented functions are flawed, such:
Find problems through Debug, such:
Find the problem and use the code to modify it.
The first practice of the instructor is to store the elements in the set to a new set. Use the iterator to iterate the old set, and then determine whether the new set contains the set elements for the current iteration. If not, add the new set. For details, see
Later, the teacher explained the method I used and reminded the students of errors. If you do not have enough careful analysis, it is easy to make mistakes.