next up previous index
Next: Assignment Up: Arrays Previous: Initialisation of Both Together   Index


Length

When an array is created its size is held in a public constant which can accessed by the expression a.length. This is useful for ensuring that the array index stays within bounds. For example
for (int i = 0; i < a.length; i++) {
    a[i] = 0;
}
initialises all elements to 0 in a safe way.



Peter Williams 2005-06-07