<<< Array initialization syntax | Index | Printing array elements >>> |
The syntax for getting the length of an array
arrayName.length
Code that puts the numbers 0 through 9 in an array
int[] values = new int[10]; for (int i = 0; i < values.length; i++) { values[i] = i; }
The field variable length contains the size of the array
The field variable length can be directly accessed in a program using the array name and the dot operator
It is a common practice for a program to keep track of the number of filled elements in an array
<<< Array initialization syntax | Index | Printing array elements >>> |