Sunday, December 14, 2008

Initial values

It's possible to assign initial values to an array when you declare it in a manner very similar to one-dimensional arrays, but with an extra level of braces. The dimension sizes are computed by the compiler from the number of values.
int[][] board = new int[][] {{0,0,0},{0,0,0},{0,0,0}};
You must assign values to an element before you use it, either with an initializer as above or assignment.

No comments: