Array Enhancements
-
The public final field iterator, containing a list of all components of the array (the iterator may not be null) has been added to the members of an array type.
-
The iterator makes an array’s components available as a final instance variable.
-
All array components may be accessed through the iterator as defined by the reference type java.util.Iterator. This is done by following the array reference with the.iterator field.
Example Expression:
ArrayVariableName.iterator
This example expression returns an iterator object on which the method next() can be called to retrieve the next element of the array starting with the first one. The method hasNext() can be also called to check if there is another element to extract from the array. Once all elements of the array have been iterated, the iterator can no longer be used and throws a java.util.NoSuchElementException exception.