I want to get a stream into an immutable list. What is the difference between following approaches and which one is better from performance perspective?
collect( Collectors.collectingAndThen(Collectors.toList(), ImmutableList::copyOf));
ImmutableList.copyOf( stream.iterator() );
collect( Collector.of( ImmutableList.Builder<Path>::new, ImmutableList.Builder<Path>::add, (l, r) -> l.addAll(r.build()), ImmutableList.Builder<Path>::build) );
A few more parameters for performance or efficiency,
There may be many entries in the list/collection.
What if I want the set sorted, using the intermediate operation
".sorted()"
with a custom comparator.- consequently, what if I add
.parallel()
to the stream