Welcome to the Linux Foundation Forum!

What is the purpose of the new keyword when building an array in Java?

I'm curious as to why an array generated in Java remains static even when we use the new keyword to declare it.
According to what I've read online (as mentioned here), the new keyword creates heap memory every time it is met during run time, thus why provide the size of the array at all during the definition?
Why can't this
int[] array1=new int[20];
can be replaced with this?
int[] array1=new int[];
I get that it does not expand automatically and that we have ArrayList for it, but what is the purpose of the term new in this? If it had to be static, it might have been specified as int array1[20], as we used to do in C and C++.
P.S. I realise this is a novice inquiry, but I am an amateur. I tried to Google but couldn't find anything comprehensive.

Categories

Upcoming Training