+ 2

Why array is using new ?

when array is declared a new word is used in Java

12th Apr 2018, 9:15 AM
Rohan Gupta
2 Answers
+ 8
It allocates the memory that will hold the array. Usually, if you hate the new keyword, and know the exact elements, you can use the shortcut method, like: int[] arr = {4, 5, 6, 7}; You are explained the 'new' keyword here in detail: https://docs.oracle.com/javase/tutorial/java/javaOO/objectcreation.html
12th Apr 2018, 9:27 AM
Dev
Dev - avatar
0
You need "new" keyword if you want to use an array without initialising it. It provides the compiler a heads up to how much memory it might require
13th Apr 2018, 7:25 AM
Twenty-three