java.lang.Object | |
↳ | org.apache.commons.collections.iterators.ArrayIterator |
Known Direct Subclasses |
Implements an java.util.Iterator Iterator over any array.
The array can be either an array of object or of primitives. If you know
that you have an object array, the
ObjectArrayIterator
class is a better choice, as it will perform better.
The iterator implements a reset()
method, allowing the reset of
the iterator back to the start if required.
Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
array | The array to iterate over | ||||||||||
endIndex | The end index to loop to | ||||||||||
index | The current iterator index | ||||||||||
startIndex | The start index to loop from |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Constructor for use with
setArray . | |||||||||||
Constructs an ArrayIterator that will iterate over the values in the
specified array.
| |||||||||||
Constructs an ArrayIterator that will iterate over the values in the
specified array from a specific start index.
| |||||||||||
Construct an ArrayIterator that will iterate over a range of values
in the specified array.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Gets the array that this iterator is iterating over.
| |||||||||||
Returns true if there are more elements to return from the array.
| |||||||||||
Returns the next element in the array.
| |||||||||||
Throws
UnsupportedOperationException . | |||||||||||
Resets the iterator back to the start index.
| |||||||||||
Sets the array that the ArrayIterator should iterate over.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Checks whether the index is valid or not.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
| |||||||||||
From interface
java.util.Iterator
| |||||||||||
From interface
org.apache.commons.collections.ResettableIterator
|
The end index to loop to
The current iterator index
The start index to loop from
Constructor for use with setArray
.
Using this constructor, the iterator is equivalent to an empty iterator
until setArray(Object)
is called to establish the array to iterate over.
Constructs an ArrayIterator that will iterate over the values in the specified array.
array | the array to iterate over. |
---|
IllegalArgumentException | if array is not an array. |
---|---|
NullPointerException | if array is null
|
Constructs an ArrayIterator that will iterate over the values in the specified array from a specific start index.
array | the array to iterate over. |
---|---|
startIndex | the index to start iterating at. |
IllegalArgumentException | if array is not an array. |
---|---|
NullPointerException | if array is null |
IndexOutOfBoundsException | if the index is invalid |
Construct an ArrayIterator that will iterate over a range of values in the specified array.
array | the array to iterate over. |
---|---|
startIndex | the index to start iterating at. |
endIndex | the index to finish iterating at. |
IllegalArgumentException | if array is not an array. |
---|---|
NullPointerException | if array is null |
IndexOutOfBoundsException | if either index is invalid |
Gets the array that this iterator is iterating over.
null
if
the no-arg constructor was used and setArray(Object)
has never
been called with a valid array.
Returns true if there are more elements to return from the array.
Returns the next element in the array.
NoSuchElementException | if all the elements in the array have already been returned |
---|
Throws UnsupportedOperationException
.
UnsupportedOperationException | always |
---|
Resets the iterator back to the start index.
Sets the array that the ArrayIterator should iterate over.
If an array has previously been set (using the single-arg constructor
or this method) then that array is discarded in favour of this one.
Iteration is restarted at the start of the new array.
Although this can be used to reset iteration, the reset()
method
is a more effective choice.
array | the array that the iterator should iterate over. |
---|
IllegalArgumentException | if array is not an array. |
---|---|
NullPointerException | if array is null
|
Checks whether the index is valid or not.
bound | the index to check |
---|---|
type | the index type (for error messages) |
IndexOutOfBoundsException | if the index is invalid |
---|