I do not understand "new" operator

Their is a difference between declaration and initialization. When we write:

int[] numbers

We are actually declaring that the variable numbers will contain an array of integers. At this moment only a variable is declared and no space is allocated. And when we write:

new int[5]

We are initializing the array and telling the program to create an integer array of 5 elements. At this moment the space will be allocated for array.

Moreover you can search for declaration and initialization for more details.

1 Like