Properties of a java for loop -


consider simple java loop:

for (int x = 0; x < bigarray.size(); x++ ) {      someobject object = (someobject) bigarray.get(x);       process(object);  }  private void   process(someobject object) {   someobject newobject = moreprocessing(object);   bigarray.add(newobject);  } 

my observation loop terminate though adding additional objects end of bigarray , bigarray getting bigger. because jre fixes value of testing condtion (in case x < bigarray.size()) before loop begins , never updates value?

the problem see op empty bigarray of type list loop terminate since has call process inside loop add elements , increase size hence condition in loop becomes true size 0 @ point.
if list not empty x < bigarray.size() compare latest length i.e. including objects added in process.
assume bigarray of type java.util.list


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

javascript - Clean way to programmatically use CSS transitions from JS? -

android - send complex objects as post php java -