Saturday, 15 January 2011

java - Is it not safe to insert into a list while iterating through it? -


Is it true that it is not safe to rotate during the list? idea? I'm not sure that personally ...

As I was hoping that concurrent modification Exceptional throwing I test it on a simple example:

  test for the public class {public static zero main (string [] args) {list & lt; Integer & gt; List = New Arrestist & lt; Integer & gt; (); List.add (1); List.add (2); List.add (3); (Iterator> Lieutenant> Integer> gt = list.iterator (); it.hasNext (); it.next ()) {System.out.println (it.toString ()); List.add (4); }}}   

Change the array list for the linked list, give the same result if I remember that the only job removals are actually correct

No comments:

Post a Comment