File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Array initialization Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Array initialization" Watch "Array initialization" New topic
Author

Array initialization

Rizwan Qadri
Ranch Hand

Joined: May 28, 2007
Posts: 40
Hi, all,

How can we initialize or use this array.

class ArrayTest
{
public static void main(String[] args)
{
int[][] values =new int[2][];
System.out.println(values[1]);
}
}

Output- null
I cant understand.
Jan van Mansum
Ranch Hand

Joined: Oct 19, 2007
Posts: 74
"values" is an array of length 2 with elements of type "array of int". It is initialized to the value {null, null}, because the length of the arrays that are the elements of "values" is unknown.

Compare what happens if you declare "values" like this:

Now the JVM will initialize the two elements of "values" to an int array with 3 elements: {{0, 0, 0},{0, 0, 0}}.

If you want to print the elements of the array, you need to access them separately:


SCJP 1.4, SCWCD 1.4
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Array initialization