Thursday, March 12, 2009

int[] array = new int[5];

Question :int[] array = new int[5];
int[] array1 = {1,2,3,4,5};
Why not new is used in second statement?
(CoreJava)

Answer :In the first line we are creating an int array with size 5 but in the second
line we are creating an int array with 5 elements in it.
In short you are initializing an int array in line one and you are creating an
int array with elements in line two.

No comments: