• 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
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

Modification on an iterator object, impacts on the List. How?

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

When we modify the structure of an ArrayList while iterating, we will get ConcurrentModificationException. To avoid it, we can perform, say remove() on an iterator object.
But how does it impact the list, at the end of an iteration/

I went throw the Java internals as well, but am clueless on how it happens.

Please throw some light on this section.
 
Sheriff
Posts: 17416
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Seems like you're asking a number of questions about library class internals. Why not go see for yourself and study the source code? You can find it here: http://grepcode.com/project/repository.grepcode.com/java/root/jdk/openjdk/

Another thing you could also do to get some clarity about the behavior and answers to the questions you're asking, is to write some test code that reflect your current understanding. If the tests fail, then you'll know that your understanding is flawed. Then, you can go back to the source code and try to see where you were wrong. Then adjust your tests to reflect your understanding again. This is often a much better way to learn and do research than have other people tell you things that may or may not be true. Not that anyone here would purposely mislead you but I think it's always wise to "Trust but verify."

reply
    Bookmark Topic Watch Topic
  • New Topic