• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Reg ConcurrentModificationException in list

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just trying to understand concurrentModificationException. When I execute the below code, instead of getting error, I'm getting output as


>> obj :: a
>> obj :: b
>> obj :: c
>> obj :: d
>> obj :: e
>> obj :: f
5[a, b, c, d, f]



Kindly explain me why..


Here is the code

package Examples;




And also when i change the comparison variable from "e" to something else say "a" or "b"(anything other than "e"), I'm getting exception.
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

I have added code tags to your post, and you can see how much better it looks
The correct question, which I don't know the answer to, is, “Why are you not suffering a concurrent modification Exception when you attempt to remove e?” You doubtless already know that you should only use the Iterator#remove() method for making any structural alterations to your List. You should expect that Exception whenever you remove anything with the List#remove(java.lang.Object) method. You can see after removing e that hasNext() is false, so f is not printed.

Otherwise: don't know. Anybody else?
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Couldn't see anything in the source to account for that error.
 
reply
    Bookmark Topic Watch Topic
  • New Topic