How works array length? Pls help | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
0

How works array length? Pls help

int[ ] intArr = new int[5]; System.out.println(intArr.length); //Outputs 5 PLS EXPLAIN THIS

7th May 2017, 9:27 PM
Spacy MTA
Spacy MTA - avatar
4 Réponses
+ 12
In the first line you define an array with 5 elements. So the array has the length 5. This is what is pronted in the 2nd line (=output). Btw, how did you manage to go through one third of the Java course and only gaining 7 xp?
7th May 2017, 9:49 PM
Tashi N
Tashi N - avatar
+ 2
Arrays are static memory allocation, so if you initialize an array with 10 elements, The length property will return the allocated size of the array. How the array length works exactly I don't know, because the implementation of the length property is no where. It is the part of the core.
7th May 2017, 10:20 PM
xCalifier
xCalifier - avatar
+ 1
i dont know :p
7th May 2017, 9:50 PM
Spacy MTA
Spacy MTA - avatar
+ 1
thanks
7th May 2017, 10:21 PM
Spacy MTA
Spacy MTA - avatar