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?

  1. collect( collectors.collectingandthen(collectors.tolist(), immutablelist::copyof));

  2. immutablelist.copyof( stream.iterator() );

  3. 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,

  1. there may many entries in list/collection.

  2. what if want set sorted, using intermediate operation ".sorted()" custom comparator.

  3. 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

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -