[java] memory allocated for the array with length zero. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

[java] memory allocated for the array with length zero.

if yes then how we define the memory allocation for this array or how much it is. https://code.sololearn.com/c4RI3jyKuW75/?ref=app

7th Apr 2018, 5:49 AM
Nitish kumar jha
Nitish kumar jha - avatar
3 Answers
+ 3
Yes, of course it would be 0. Arrays are the part of Object type data of Java. There are primarily two types of data - Primitive and Object. Object includes Arrays, ArrayLists, Scanner and Strings. Primitives include int, char, boolean, long and more. What happens is when we create an object with a size such as 0, memory is allocated to that object in the computer's memory, but however in accordance with its size. For example, you say int[] arr = new int[0]; Now the length of arr is 0 because there is nothing actually stored in it. You see if it is int[] arr = new int[5] ... the length will be 5. The object's indexes are null because no value is assigned, however the size is not null ! You could better get by relating to this example... String s = ""; System.out.print(s.length()); // Ouputs : 0 The length is 0 because there is nothing in the String. It contains nothing. However, it is not null. I suggest you to learn Object data. That could clarify your doubts.
7th Apr 2018, 6:25 AM
Aaron Stone
Aaron Stone - avatar
+ 2
That's kinda unknowable I guess. If it says 0, I guess it's none. Until you store something in it, it won't be used.
7th Apr 2018, 6:36 AM
Aaron Stone
Aaron Stone - avatar
+ 1
Aaron Stone but question is that what's the mean of 0 space in (how much bits ) memory area. but thanks for your help I read object data
7th Apr 2018, 6:33 AM
Nitish kumar jha
Nitish kumar jha - avatar