public class Demo {
public static void main(String[] args) {
int array[]=new int[2];
System.out.println(array);
}
}
This an example. Can anybody explain this.
public class Demo {
public static void main(String[] args) {
int array[]=new int[2];
System.out.println(array);
}
}
This an example. Can anybody explain this.
You just defined the array and java by default initialized that array context i.e. array[0] and array[1] with default value i.e. 0.
When you will print the array it will just print the type of Array i.e. Int array followed by hashCode something like I@32324.
// declares an array of integers
int[] anArray;
// allocates memory for 10 integers
anArray = new int[10];
//declares an array of integers and allocates memory for 2 integers
int array[]=new int[2];
And if you want to print that thing use --> this <--
//print the content of the array
System.out.println(Arrays.toString(array));
Because this :
System.out.println(array);
is not going to print the content of your array, it will print the memory address of the array.