for (Object obj : list) {
if (obj.getCode().equals("something"))
list.remove(obj);
}
To avoid this exception, the trick is to delete/add an item through the iterator, but not the collection. Here is the example:
Iterator it = list.iterator();
while (it.hasNext()) {
Object obj = (Object)it.next();
if (obj.getCode().equals("something")) {
it.remove();
}
}
Hope this helps.
2 comments:
excellent article. But I need more written
Great article; short, concise, to the point and accurate. Nice one.
Post a Comment