Exception: Java. util. concurrentmodificationexception

Source: Internet
Author: User
Quote:
exception: Java. util. concurrentmodificationexception

During map or collection, do not use their APIs to directly modify the content of the set. To modify the content, use the remove () function of iterator () method, for example:

Public void setreparation (reparation) {
for (iterator it = This. reparations. iterator (); it. hasnext ();) {// reparations is collection
reparation REPA = (Reparation) it. next ();
If (REPA. GETID () = reparation. GETID () {
This. reparations. remove (REPA);
This. reparations. add (Reparation);
}< BR >}

concurrentmodificationexception is reported during the runtime as shown in the preceding code. You can modify the statement as follows:

Public void setreparation (reparation) {
Boolean flag = false;
for (iterator it = This. reparations. iterator (); it. hasnext ();) {// reparations is collection
reparation REPA = (Reparation) it. next ();
If (REPA. GETID () = reparation. GETID () {
it. remove ();
flag = true;
break;
}< br> If (FLAG) {
This. reparations. add (Reparation);
}< BR >}

specific reference: http://gceclub.sun.com.cn/yuanchuang/week-14/iterator.html

*
......
[read the full text]

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.