Skip to content

Initializing an Empty Array#

If you don't want to provide all of the array entries right at the start of your program, you still must tell your program, how large your array is going to be. Up until now, we always declared and initialized our array on one line. In those cases, your program knows exactly how many entries will be in your array and thus it knows how much memory it needs to set aside for it. With a little hint, we can actually declare an empty array:

int[] weirdFish = new int[25];

That variable weirdFish is now an integer array that can contain 25 integer numbers. We did not assign any of these numbers, but there's space for them and we can set them later.