As an example of storing strings in ArrayList, I do it myself before the instructor in the video lectures. The subject requirements are as follows
My own practice is to iterate through the collection with a for loop to get the elements in the collection. All elements after the current index are compared if they are identical and removed if the same, but after the code is complete, the implemented functionality is flawed, such as:
Find problems with debug, such as:
Modify the code in use after finding the problem
The first way to explain a teacher is to store the elements in the collection in a new collection. Iterate over the old collection with an iterator and then determine whether the new collection contains the collection element that will be the current iteration, and if it is not included, add it. Specific as
Later, the teacher also explained the method I used, reminding the students of the error-prone place. If not careful enough analysis, this is a very easy place to go wrong
Java Foundation 16th Day: Remove duplicate content from the collection