How to fill two-dimensional array using java enhanced loop?

Posted by Shark on Stack Overflow See other posts from Stack Overflow or by Shark
Published on 2010-04-14T09:24:14Z Indexed on 2010/04/14 9:33 UTC
Read the original article Hit count: 245

Filed under:
|

Basically, I am trying this, but this only leaves array filled with zeros. I know how to fill it with normal for loop (such as for (int i = 0; i < array.length; i++) and so on), but why is my variant is not working? Any help would be appreciated.

char[][] array = new char[x][y];
for (char[] row : array)
    for (char element : row)
        element = '~';

© Stack Overflow or respective owner

Related posts about array

Related posts about java