Web Project Error-java.util.concurrentmidificationexception

Source: Internet
Author: User

Source:

    1. iterator<string> Iterator = List.iterator ();
    2. Synchronized (synobject) {
    3. While (Iterator.hasnext ()) {
    4. String str = Iterator.next ();
    5. if (Del.contains (str)) {
    6. Iterator.remove ();
    7. }
    8. }
    9. }

Cause of Error:

You cannot remove an element from a list collection while it is being traversed.

Workaround:

1. You can install the element you want to delete with another list, and then remove it by the end of the traversal.

2. You can also add a break after the deletion, that is, when you find the object to be deleted, the deletion stops and the collection is not traversed.

Web Project Error-java.util.concurrentmidificationexception

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.