Contents of array of primitive type

I am trying to find out if an int array contains NULL or 0 (the value) when it is first declared and instantiated with 5 elements.

int[] aray =newint[5];

System.out.println(aray[3]);

Output:

0

Question: does the output mean that the value is assigned to all the elements when the identifier aray is assigned to the new array?

Then how can we find out if the array contains NULL or otherwise.

Thanks.

[549 byte] By [missing_linka] at [2007-11-26 20:42:15]
# 1

Well you kind of answered your own question. If you looped over the array and printed out each element of the array you will see what is stored as a default value. Try this.

boolean[] bools = new boolean[5];

for(int index = 0; index < bools.length; index++) {

System.out.println(bools[index]);

}

floundera at 2007-7-10 2:01:39 > top of Java-index,Java Essentials,New To Java...
# 2
A null would most probably be happening to a "pointer" variable, which points to an instance of object rather than primitive type.
Icycoola at 2007-7-10 2:01:41 > top of Java-index,Java Essentials,New To Java...
# 3

int[] aray = new int[5];

does the output mean that the value is assigned to all the elements when the identifier aray is assigned to the new array?

Answer: if it is an array of any primitive type, all array elements are initialized to its default value. if it is an array of any reference type, all array elements are initialized to null.

try following

Integer[] aray = new Integer[5];

tapan_javaprogrammera at 2007-7-10 2:01:41 > top of Java-index,Java Essentials,New To Java...
# 4
Thanks everyone, got that part.I read somwhere that at the point when the (primitive) array is declared ie. int[] aray; since the identifier aray does not point to anything, "it is" NULL in concept.Thanks everyone!
missing_linka at 2007-7-10 2:01:42 > top of Java-index,Java Essentials,New To Java...