You can use the following combination of standard functions:
StreamSupport.stream(Spliterators.spliteratorUnknownSize(CollectionUtils.toIterator(enumeration), Spliterator.IMMUTABLE), parallel)
You may also add more characteristics like NONNULL
or DISTINCT
.
After applying static imports this will become more readable:
stream(spliteratorUnknownSize(toIterator(enumeration), IMMUTABLE), false)
now you have a standard Java 8 Stream to be used in any way! You may pass true
for parallel processing.
To convert from Enumeration to Iterator use any of:
CollectionUtils.toIterator()
from Spring 3.2 or you can use
IteratorUtils.asIterator()
from Apache Commons Collections 3.2
Iterators.forEnumeration()
from Google Guava