Java basics: 16th days: Remove duplicate content from the collection, java 16th days

Source: Internet
Author: User

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.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.