Top Description Fields Constructors Methods
org.apache.commons.collections4.iterators

public Class ArrayIterator<E>

extends Object
implements ResettableIterator<E>
Class Inheritance
All Implemented Interfaces
org.apache.commons.collections4.ResettableIterator, java.util.Iterator
Known Direct Subclasses
org.apache.commons.collections4.iterators.ArrayListIterator
Type Parameters
<E>
the type of elements returned by this iterator
Imports
java.lang.reflect.Array, java.util.NoSuchElementException, org.apache.commons.collections4.ResettableIterator

Implements an 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.

Since
1.0

Field Summary

Modifier and TypeField and Description
pack-priv final Object
array

The array to iterate over

pack-priv final int
endIndex

The end index to loop to

pack-priv int
index

The current iterator index

pack-priv final int
startIndex

The start index to loop from

Constructor Summary

AccessConstructor and Description
public
ArrayIterator(final Object
the array to iterate over.
array
)

Constructs an ArrayIterator that will iterate over the values in the specified array.

public
ArrayIterator(final Object
the array to iterate over.
array
,
final int
the index to start iterating at.
startIndex
)

Constructs an ArrayIterator that will iterate over the values in the specified array from a specific start index.

public
ArrayIterator(final Object
the array to iterate over.
array
,
final int
the index to start iterating at.
startIndex
,
final int
the index to finish iterating at.
endIndex
)

Construct an ArrayIterator that will iterate over a range of values in the specified array.

Method Summary

Modifier and TypeMethod and Description
protected void
checkBound(final int
the index to check
bound
,
final int
the length of the array
len
,
final String
the index type (for error messages)
type
)

Checks whether the index is valid or not.

public Object

Returns:

the array this iterator iterates over.
getArray
()

Gets the array that this iterator is iterating over.

public int

Returns:

the end index
getEndIndex
()

Gets the end index to loop to.

public int

Returns:

the start index
getStartIndex
()

Gets the start index to loop from.

public boolean

Returns:

true if there is a next element to return
hasNext
()

Implements java.util.Iterator.hasNext.

Returns true if there are more elements to return from the array.
public E

Returns:

the next element in the array
next
()

Implements java.util.Iterator.next.

Returns the next element in the array.
public void
public void
reset()

Implements org.apache.commons.collections4.ResettableIterator.reset.

Resets the iterator back to the start index.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

arrayback to summary
pack-priv final Object array

The array to iterate over

endIndexback to summary
pack-priv final int endIndex

The end index to loop to

indexback to summary
pack-priv int index

The current iterator index

startIndexback to summary
pack-priv final int startIndex

The start index to loop from

Constructor Detail

ArrayIteratorback to summary
public ArrayIterator(final Object array)

Constructs an ArrayIterator that will iterate over the values in the specified array.

Parameters
array:Object

the array to iterate over.

Exceptions
IllegalArgumentException:
if array is not an array.
NullPointerException:
if array is null
ArrayIteratorback to summary
public ArrayIterator(final Object array, final int startIndex)

Constructs an ArrayIterator that will iterate over the values in the specified array from a specific start index.

Parameters
array:Object

the array to iterate over.

startIndex:int

the index to start iterating at.

Exceptions
IllegalArgumentException:
if array is not an array.
NullPointerException:
if array is null
IndexOutOfBoundsException:
if the index is invalid
ArrayIteratorback to summary
public ArrayIterator(final Object array, final int startIndex, final int endIndex)

Construct an ArrayIterator that will iterate over a range of values in the specified array.

Parameters
array:Object

the array to iterate over.

startIndex:int

the index to start iterating at.

endIndex:int

the index to finish iterating at.

Exceptions
IllegalArgumentException:
if array is not an array.
NullPointerException:
if array is null
IndexOutOfBoundsException:
if either index is invalid

Method Detail

checkBoundback to summary
protected void checkBound(final int bound, final int len, final String type)

Checks whether the index is valid or not.

Parameters
bound:int

the index to check

len:int

the length of the array

type:String

the index type (for error messages)

Exceptions
IndexOutOfBoundsException:
if the index is invalid
getArrayback to summary
public Object getArray()

Gets the array that this iterator is iterating over.

Returns:Object

the array this iterator iterates over.

getEndIndexback to summary
public int getEndIndex()

Gets the end index to loop to.

Returns:int

the end index

Since
4.0
getStartIndexback to summary
public int getStartIndex()

Gets the start index to loop from.

Returns:int

the start index

Since
4.0
hasNextback to summary
public boolean hasNext()

Implements java.util.Iterator.hasNext.

Returns true if there are more elements to return from the array.

Returns:boolean

true if there is a next element to return

Annotations
@Override
nextback to summary
public E next()

Implements java.util.Iterator.next.

Returns the next element in the array.

Returns:E

the next element in the array

Annotations
@Override
@SuppressWarnings:unchecked
Exceptions
NoSuchElementException:
if all the elements in the array have already been returned
removeback to summary
public void remove()

Overrides default java.util.Iterator.remove.

Throws UnsupportedOperationException.

Annotations
@Override
Exceptions
UnsupportedOperationException:
always
resetback to summary
public void reset()

Implements org.apache.commons.collections4.ResettableIterator.reset.

Resets the iterator back to the start index.

Annotations
@Override