You can use the following combination of standard functions:
StreamSupport.stream(Spliterators.spliteratorUnknownSize(CollectionUtils.toIterator(enumeration), Spliterator.IMMUTABLE), parallel)
You can also add additional features such as NONNULL or DISTINCT .
After applying static imports, this will become more readable:
stream(spliteratorUnknownSize(toIterator(enumeration), IMMUTABLE), false)
you now have a standard Java 8 thread that you can use in any way! You can pass true for parallel processing.
To convert from Enumeration to Iterator, use any of:
CollectionUtils.toIterator() from Spring 3.2 or you can useIteratorUtils.asIterator() from the Apache Commons 3.2 collectionIterators.forEnumeration() by Google Guava
Arne Burmeister Nov 26 '14 at 8:53 2014-11-26 08:53
source share