How to return the next element from a spliterator in java?
I want to get the next element from a spliterator, not just “perform action” on the next element. For example by implementing the following method.
T getnext(Spliterator s) {
}
All search results I found just said that tryAdvance() was like a combination of an iterator hasNext() and next(), except that is a BIG LIE because I can’t get the next element, just “perform the action on next element”.
Kristen Berry
public static T getNext(Spliterator spliterator) {
List result = new ArrayList(1);
if (spliterator.tryAdvance(result::add)) {
return result.get(0);
} else {
return null;
}
}