I want to convert a Spliterator<T>
into a List<T>
in Java.
What is the best idiom to do that? I'm currently using the following code:
List<T> list = new ArrayList<>();
spliterator.forEachRemaining(list::add);
Is there a simpler / faster way?
You can use this:
StreamSupport.stream(spliterator, false).collect(Collectors.toList())