| 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 <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 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 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 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 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 nullCopyright © 2015. All rights reserved.