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?
It contains the allocated size, 10
. The unassigned indexes will contain the default value which is 0
for int
.