In your case, you cannot. For-each hides the iterator on the underlying collection, so here you cannot figure out what position in "numbers" you currently are in when you try "initializing" the array. This is one use case the "advanced" loop isn't made for.