The best way to collect the Java-8 Stream to Guava ImmutableList -
i want stream immutable list. difference between following approaches , 1 better 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 performance or efficiency,
there may many entries in list/collection.
what if want set sorted, using intermediate operation
".sorted()"
custom comparator.- consequently, if add
.parallel()
stream
i expect 1) efficient: going via builders seems less readable , unlikely win on normal tolist()
, , copying iterator discards sizing information.
(but guava working on adding support java 8 things this, might wait for.)
Comments
Post a Comment