public class ArrayIterator extends Object implements 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.
Modifier and Type | Field and Description |
---|---|
protected Object |
array
The array to iterate over
|
protected int |
endIndex
The end index to loop to
|
protected int |
index
The current iterator index
|
Constructor and Description |
---|
ArrayIterator(Object array)
Constructs an ArrayIterator that will iterate over the values in the
specified array.
|
Modifier and Type | Method and Description |
---|---|
protected void |
checkBound(int bound,
String type)
Checks whether the index is valid or not.
|
Object |
getArray()
Gets the array that this iterator is iterating over.
|
boolean |
hasNext()
Returns true if there are more elements to return from the array.
|
Object |
next()
Returns the next element in the array.
|
void |
remove()
Throws
UnsupportedOperationException . |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
forEachRemaining
protected Object array
protected int endIndex
protected int index
public ArrayIterator(Object array)
array
- the array to iterate over.IllegalArgumentException
- if array
is not an array.NullPointerException
- if array
is null
protected void checkBound(int bound, String type)
bound
- the index to checktype
- the index type (for error messages)IndexOutOfBoundsException
- if the index is invalidpublic boolean hasNext()
public Object next()
next
in interface Iterator
NoSuchElementException
- if all the elements in the array
have already been returnedpublic void remove()
UnsupportedOperationException
.remove
in interface Iterator
UnsupportedOperationException
- alwayspublic Object getArray()
null
if
the no-arg constructor was used and setArray(Object)
has never
been called with a valid array.Copyright © 2001–2017 JBoss by Red Hat. All rights reserved.