Array Length in Java
Posted By: Anonymous
I declared an array as shown below:
int[] arr = new int[10];
Then I assigned following values to the array:
arr[0] = 1;
arr[1] = 2;
arr[2] = 3;
arr[3] = 4;
Then I declared and initialized an integer variable:
int arrayLength = arr.length;
This will be useful to find actual size but is there any method to find logical size of the array?
Solution
It contains the allocated size, 10
. The unassigned indexes will contain the default value which is 0
for int
.
Answered By: Anonymous
Disclaimer: This content is shared under creative common license cc-by-sa 3.0. It is generated from StackExchange Website Network.