Initializing an array in Java using the 'advanced' for each loop

Posted by Corleone on Stack Overflow See other posts from Stack Overflow or by Corleone
Published on 2010-03-31T21:01:05Z Indexed on 2010/03/31 21:03 UTC
Read the original article Hit count: 175

Filed under:
|
|
|

Is it possible to initialise an array in Java using the 'advanced' for loop?

e.g.

    Integer[ ] numbers = new Integer[20];
    int counter = 0;
    for ( Integer i : numbers )
    {
        i = counter++;
    }

    for ( Integer i : numbers )
    {
        System.out.println(i);
    }

This prints all nulls, why is that?

© Stack Overflow or respective owner

Related posts about java

Related posts about for-loop