Properties of a java for loop

Consider a simple java for loop:

for (int x = 0; x < bigArray.size(); x++ ) {
     Someobject object = (Someobject) bigArray.get(x);

private void   process(Someobject object) {
  Someobject newobject = moreProcessing(object);

My observation is that the for loop will terminate even though I am adding additional objects to the end of bigArray and bigArray is constantly getting bigger. Is this because the JRE fixes the value of the testing condtion (in this case x < bigArray.size()) before the for loop begins and never updates this value?


The only problem I see with the OP is that for an empty bigArray of type List the loop will terminate since it has to call process inside the loop to add elements and increase the size hence the condition in the for loop becomes true but the size is 0 at that point. If the list is not empty then the x < bigArray.size() will always compare to the latest length i.e. including the objects added in process. I assume that bigArray is of type java.util.List

In most cases test condition will be evaluated before start of each iteration.

More here

Need Your Help

Best way to load external content to site (I own all sites) (no iframes?)

php jquery html iframe load

I have an ever growing medley of websites that I own (WordPress for the most part if that helps).

Is it possible to collect results from callbacks through coffeescript comprehensions?

coffeescript list-comprehension for-comprehension

Suppose I have array of objects, each have some asynchronous readValue function, which accepts callback as its parameter, which will be fired when value is available for this object.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.