Modifier and Type | Method and Description |
---|---|
static <E> Iterator<E> |
asIterator(Enumeration<E> en)
Returns an
Iterator that traverses the remaining elements
covered by the passed enumeration. |
static <T> Iterator<T> |
emptyIterator()
Returns an iterator that has no elements.
|
static <E> void |
forEachRemaining(Iterator<E> it,
Consumer<? super E> action)
Performs the given action for each remaining element until all elements
have been processed or the action throws an exception.
|
static void |
forEachRemaining(PrimitiveIterator.OfDouble it,
DoubleConsumer action)
Performs the given action for each remaining element until all elements
have been processed or the action throws an exception.
|
static void |
forEachRemaining(PrimitiveIterator.OfInt it,
IntConsumer action)
Performs the given action for each remaining element until all elements
have been processed or the action throws an exception.
|
static void |
forEachRemaining(PrimitiveIterator.OfLong it,
LongConsumer action)
Performs the given action for each remaining element until all elements
have been processed or the action throws an exception.
|
public static <E> void forEachRemaining(Iterator<E> it, Consumer<? super E> action)
The behavior of an iterator is unspecified if the action modifies the underlying
source of elements in any way (even by calling the remove
method or other mutator methods of Iterator
subtypes), unless an overriding
class has specified a concurrent modification policy.
Subsequent behavior of an iterator is unspecified if the action throws an exception.
The implementation behaves as if:
while (it.hasNext())
action.accept(it.next());
E
- the type of the elements for the passed iteratorit
- the Iterator
whose remaining elements should be processedaction
- The action to be performed for each elementNullPointerException
- if the specified iterator is nullNullPointerException
- if the specified action is nullpublic static void forEachRemaining(PrimitiveIterator.OfInt it, IntConsumer action)
The behavior of an iterator is unspecified if the action modifies the underlying
source of elements in any way (even by calling the remove
methodor other mutator methods of Iterator
subtypes), unless an overriding
class has specified a concurrent modification policy.
Subsequent behavior of an iterator is unspecified if the action throws an exception.
The implementation behaves as if:
while (it.hasNext())
action.accept(it.next());
it
- the Iterator
whose remaining elements should be processedaction
- The action to be performed for each elementNullPointerException
- if the specified iterator is nullNullPointerException
- if the specified action is nullpublic static void forEachRemaining(PrimitiveIterator.OfLong it, LongConsumer action)
The behavior of an iterator is unspecified if the action modifies the underlying
source of elements in any way (even by calling the remove
method or other mutator methods of Iterator
subtypes), unless an overriding
class has specified a concurrent modification policy.
Subsequent behavior of an iterator is unspecified if the action throws an exception.
The implementation behaves as if:
while (it.hasNext())
action.accept(it.next());
it
- the Iterator
whose remaining elements should be processedaction
- The action to be performed for each elementNullPointerException
- if the specified iterator is nullNullPointerException
- if the specified action is nullpublic static void forEachRemaining(PrimitiveIterator.OfDouble it, DoubleConsumer action)
The behavior of an iterator is unspecified if the action modifies the underlying
source of elements in any way (even by calling the remove
method or other mutator methods of Iterator
subtypes), unless an overriding
class has specified a concurrent modification policy.
Subsequent behavior of an iterator is unspecified if the action throws an exception.
The implementation behaves as if:
while (it.hasNext())
action.accept(it.next());
it
- the Iterator
whose remaining elements should be processedaction
- The action to be performed for each elementNullPointerException
- if the specified iterator is nullNullPointerException
- if the specified action is nullpublic static <E> Iterator<E> asIterator(Enumeration<E> en)
Iterator
that traverses the remaining elements
covered by the passed enumeration. Traversal is undefined if any
methods are called on the passed enumeration after the call to
asIterator
.
API Note:
This method is intended to help adapt code that produces
Enumeration
instances to code that consumes Iterator
instances. For example, the JarFile.entries()
method returns an Enumeration<JarEntry>
.
This can be turned into an Iterator
, and then the
forEachRemaining()
method can be used:
JarFile jarFile = ... ;
Iterators.forEachRemaining(Iterators.asIterator(jarFile.entries()), entry -> ... );
Implementation Requirements:
The default implementation returns an Iterator
whose
hasNext
method calls the passed Enumeration's
hasMoreElements
method, whose next
method calls the passed Enumeration's nextElement
method,
and whose remove
method throws
UnsupportedOperationException
.
E
- the type of the elements for the passed enumerationen
- the Enumeration
whose remaining elements should be processedNullPointerException
- if the specified enumeration is nullpublic static <T> Iterator<T> emptyIterator()
hasNext
always returns false
.next
always throws
NoSuchElementException
.remove
always throws
IllegalStateException
.Implementations of this method are permitted, but not required, to return the same object from multiple invocations.
T
- type of elements, if there were any, in the iteratorCopyright © 2018. All rights reserved.