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]