java 8 stream tutorial benjamin winterberg

of 27/27
4/18/2016 Java 8 Stream Tutorial Benjamin Winterberg http://winterbe.com/posts/2014/07/31/java8streamtutorialexamples/ 1/27 Java 8 Stream Tutorial July 31, 2014 Bitbucket is how professional software teams do Git. FREE unlimited private repos. ads via Carbon This exampledriven tutorial gives an indepth overview about Java 8 streams. When I first read about the Stream API, I was confused about the name since it sounds similar to InputStream and OutputStream from Java I/O. But Java 8 streams are a completely different thing. Streams are Monads, thus playing a big part in bringing functional programming to Java: In functional programming, a monad is a structure that represents computations defined as sequences of steps. A type with a monad structure defines what it means to chain operations, or nest functions of that type together. This guide teaches you how to work with Java 8 streams and how to use the different kind of available stream operations. You'll learn about the processing order and how the ordering of stream operations affect runtime performance. The more powerful stream operations reduce , collect and flatMap are covered in detail. The tutorial ends with an indepth look at parallel streams. If you're not yet familiar with Java 8 lambda expressions, functional interfaces and method references, you probably want to read my Java 8 Tutorial first before starting with this tutorial. UPDATE I'm currently working on a JavaScript implementation of the Java 8 Streams API W

Post on 14-Apr-2017

245 views

Category:

Education

4 download

Embed Size (px)

TRANSCRIPT

  • 4/18/2016 Java8StreamTutorialBenjaminWinterberg

    http://winterbe.com/posts/2014/07/31/java8streamtutorialexamples/ 1/27

    Java8StreamTutorialJuly31,2014

    BitbucketishowprofessionalsoftwareteamsdoGit.FREEunlimitedprivaterepos.adsviaCarbon

    ThisexampledriventutorialgivesanindepthoverviewaboutJava8streams.WhenIfirst

    readaboutthe Stream API,Iwasconfusedaboutthenamesinceitsoundssimilarto

    InputStream and OutputStream fromJavaI/O.ButJava8streamsareacompletely

    differentthing.StreamsareMonads,thusplayingabigpartinbringingfunctional

    programmingtoJava:

    Infunctionalprogramming,amonadisastructurethatrepresentscomputations

    definedassequencesofsteps.Atypewithamonadstructuredefineswhatitmeans

    tochainoperations,ornestfunctionsofthattypetogether.

    ThisguideteachesyouhowtoworkwithJava8streamsandhowtousethedifferentkind

    ofavailablestreamoperations.You'lllearnabouttheprocessingorderandhowthe

    orderingofstreamoperationsaffectruntimeperformance.Themorepowerfulstream

    operations reduce , collect and flatMap arecoveredindetail.Thetutorialendswith

    anindepthlookatparallelstreams.

    Ifyou'renotyetfamiliarwithJava8lambdaexpressions,functionalinterfacesandmethod

    references,youprobablywanttoreadmyJava8Tutorialfirstbeforestartingwiththis

    tutorial.

    UPDATEI'mcurrentlyworkingonaJavaScriptimplementationoftheJava8StreamsAPI

    W

    hhttp://synd.co/1SODAKmhhttp://synd.co/1SODAKmhttp://carbonads.net/http://en.wikipedia.org/wiki/Monad_%28functional_programming%29http://winterbe.com/posts/2014/03/16/java-8-tutorial/http://winterbe.com/

  • 4/18/2016 Java8StreamTutorialBenjaminWinterberg

    http://winterbe.com/posts/2014/07/31/java8streamtutorialexamples/ 2/27

    forthebrowser.IfI'vedrawnyourinterestcheckoutStream.jsonGitHub.YourFeedback

    ishighlyappreciated.

    Howstreamswork

    Astreamrepresentsasequenceofelementsandsupportsdifferentkindofoperationsto

    performcomputationsuponthoseelements:

    ListmyList=Arrays.asList("a1","a2","b1","c2","c1");

    myList.stream().filter(s>s.startsWith("c")).map(String::toUpperCase).sorted().forEach(System.out::println);

    //C1//C2

    Streamoperationsareeitherintermediateorterminal.Intermediateoperationsreturna

    streamsowecanchainmultipleintermediateoperationswithoutusingsemicolons.

    Terminaloperationsareeithervoidorreturnanonstreamresult.Intheaboveexample

    filter , map and sorted areintermediateoperationswhereas forEach isaterminal

    operation.ForafulllistofallavailablestreamoperationsseetheStreamJavadoc.Sucha

    chainofstreamoperationsasseenintheexampleaboveisalsoknownasoperation

    pipeline.

    Moststreamoperationsacceptsomekindoflambdaexpressionparameter,afunctional

    interfacespecifyingtheexactbehavioroftheoperation.Mostofthoseoperationsmustbe

    bothnoninterferingandstateless.Whatdoesthatmean?

    Afunctionisnoninterferingwhenitdoesnotmodifytheunderlyingdatasourceofthe

    stream,e.g.intheaboveexamplenolambdaexpressiondoesmodify myList byadding

    orremovingelementsfromthecollection.

    Afunctionisstatelesswhentheexecutionoftheoperationisdeterministic,e.g.inthe

    aboveexamplenolambdaexpressiondependsonanymutablevariablesorstatesfrom

    theouterscopewhichmightchangeduringexecution.

    Differentkindofstreams

    https://github.com/winterbe/streamjshttp://docs.oracle.com/javase/8/docs/api/java/util/stream/Stream.htmlhttp://docs.oracle.com/javase/8/docs/api/java/util/stream/package-summary.html#NonInterferencehttp://docs.oracle.com/javase/8/docs/api/java/util/stream/package-summary.html#Statelessness

  • 4/18/2016 Java8StreamTutorialBenjaminWinterberg

    http://winterbe.com/posts/2014/07/31/java8streamtutorialexamples/ 3/27

    Differentkindofstreams

    Streamscanbecreatedfromvariousdatasources,especiallycollections.ListsandSets

    supportnewmethods stream() and parallelStream() toeithercreateasequentialora

    parallelstream.Parallelstreamsarecapableofoperatingonmultiplethreadsandwillbe

    coveredinalatersectionofthistutorial.Wefocusonsequentialstreamsfornow:

    Arrays.asList("a1","a2","a3").stream().findFirst().ifPresent(System.out::println);//a1

    Callingthemethod stream() onalistofobjectsreturnsaregularobjectstream.Butwe

    don'thavetocreatecollectionsinordertoworkwithstreamsasweseeinthenextcode

    sample:

    Stream.of("a1","a2","a3").findFirst().ifPresent(System.out::println);//a1

    Justuse Stream.of() tocreateastreamfromabunchofobjectreferences.

    BesidesregularobjectstreamsJava8shipswithspecialkindsofstreamsforworkingwith

    theprimitivedatatypes int , long and double .Asyoumighthaveguessedit's

    IntStream , LongStream and DoubleStream .

    IntStreamscanreplacetheregularforlooputilizing IntStream.range() :

    IntStream.range(1,4).forEach(System.out::println);

    //1//2//3

    Allthoseprimitivestreamsworkjustlikeregularobjectstreamswiththefollowing

    differences:Primitivestreamsusespecializedlambdaexpressions,e.g. IntFunction

    insteadof Function or IntPredicate insteadof Predicate .Andprimitivestreams

    supporttheadditionalterminalaggregateoperations sum() and average() :

  • 4/18/2016 Java8StreamTutorialBenjaminWinterberg

    http://winterbe.com/posts/2014/07/31/java8streamtutorialexamples/ 4/27

    Arrays.stream(newint[]{1,2,3}).map(n>2*n+1).average().ifPresent(System.out::println);//5.0

    Sometimesit'susefultotransformaregularobjectstreamtoaprimitivestreamorvice

    versa.Forthatpurposeobjectstreamssupportthespecialmappingoperations

    mapToInt() , mapToLong() and mapToDouble :

    Stream.of("a1","a2","a3").map(s>s.substring(1)).mapToInt(Integer::parseInt).max().ifPresent(System.out::println);//3

    Primitivestreamscanbetransformedtoobjectstreamsvia mapToObj() :

    IntStream.range(1,4).mapToObj(i>"a"+i).forEach(System.out::println);

    //a1//a2//a3

    Here'sacombinedexample:thestreamofdoublesisfirstmappedtoanintstreamand

    thanmappedtoanobjectstreamofstrings:

    Stream.of(1.0,2.0,3.0).mapToInt(Double::intValue).mapToObj(i>"a"+i).forEach(System.out::println);

    //a1//a2//a3

    ProcessingOrder

    Nowthatwe'velearnedhowtocreateandworkwithdifferentkindsofstreams,let'sdive

    deeperintohowstreamoperationsareprocessedunderthehood.

  • 4/18/2016 Java8StreamTutorialBenjaminWinterberg

    http://winterbe.com/posts/2014/07/31/java8streamtutorialexamples/ 5/27

    Animportantcharacteristicofintermediateoperationsislaziness.Lookatthissample

    whereaterminaloperationismissing:

    Stream.of("d2","a2","b1","b3","c").filter(s>{System.out.println("filter:"+s);returntrue;});

    Whenexecutingthiscodesnippet,nothingisprintedtotheconsole.Thatisbecause

    intermediateoperationswillonlybeexecutedwhenaterminaloperationispresent.

    Let'sextendtheaboveexamplebytheterminaloperation forEach :

    Stream.of("d2","a2","b1","b3","c").filter(s>{System.out.println("filter:"+s);returntrue;}).forEach(s>System.out.println("forEach:"+s));

    Executingthiscodesnippetresultsinthedesiredoutputontheconsole:

    filter:d2forEach:d2filter:a2forEach:a2filter:b1forEach:b1filter:b3forEach:b3filter:cforEach:c

    Theorderoftheresultmightbesurprising.Anaiveapproachwouldbetoexecutethe

    operationshorizontallyoneafteranotheronallelementsofthestream.Butinsteadeach

    elementmovesalongthechainvertically.Thefirststring"d2"passes filter then

    forEach ,onlythenthesecondstring"a2"isprocessed.

    Thisbehaviorcanreducetheactualnumberofoperationsperformedoneachelement,as

    weseeinthenextexample:

    Stream.of("d2","a2","b1","b3","c")

  • 4/18/2016 Java8StreamTutorialBenjaminWinterberg

    http://winterbe.com/posts/2014/07/31/java8streamtutorialexamples/ 6/27

    .map(s>{System.out.println("map:"+s);returns.toUpperCase();}).anyMatch(s>{System.out.println("anyMatch:"+s);returns.startsWith("A");});

    //map:d2//anyMatch:D2//map:a2//anyMatch:A2

    Theoperation anyMatch returns true assoonasthepredicateappliestothegiveninput

    element.Thisistrueforthesecondelementpassed"A2".Duetotheverticalexecutionof

    thestreamchain, map hasonlytobeexecutedtwiceinthiscase.Soinsteadofmapping

    allelementsofthestream, map willbecalledasfewaspossible.

    Whyordermatters

    Thenextexampleconsistsoftwointermediateoperations map and filter andthe

    terminaloperation forEach .Let'sonceagaininspecthowthoseoperationsarebeing

    executed:

    Stream.of("d2","a2","b1","b3","c").map(s>{System.out.println("map:"+s);returns.toUpperCase();}).filter(s>{System.out.println("filter:"+s);returns.startsWith("A");}).forEach(s>System.out.println("forEach:"+s));

    //map:d2//filter:D2//map:a2//filter:A2//forEach:A2//map:b1//filter:B1//map:b3//filter:B3//map:c//filter:C

  • 4/18/2016 Java8StreamTutorialBenjaminWinterberg

    http://winterbe.com/posts/2014/07/31/java8streamtutorialexamples/ 7/27

    Asyoumighthaveguessedboth map and filter arecalledfivetimesforeverystringin

    theunderlyingcollectionwhereas forEach isonlycalledonce.

    Wecangreatlyreducetheactualnumberofexecutionsifwechangetheorderofthe

    operations,moving filter tothebeginningofthechain:

    Stream.of("d2","a2","b1","b3","c").filter(s>{System.out.println("filter:"+s);returns.startsWith("a");}).map(s>{System.out.println("map:"+s);returns.toUpperCase();}).forEach(s>System.out.println("forEach:"+s));

    //filter:d2//filter:a2//map:a2//forEach:A2//filter:b1//filter:b3//filter:c

    Now, map isonlycalledoncesotheoperationpipelineperformsmuchfasterforlarger

    numbersofinputelements.Keepthatinmindwhencomposingcomplexmethodchains.

    Let'sextendtheaboveexamplebyanadditionaloperation, sorted :

    Stream.of("d2","a2","b1","b3","c").sorted((s1,s2)>{System.out.printf("sort:%s;%s\n",s1,s2);returns1.compareTo(s2);}).filter(s>{System.out.println("filter:"+s);returns.startsWith("a");}).map(s>{System.out.println("map:"+s);returns.toUpperCase();}).forEach(s>System.out.println("forEach:"+s));

    Sortingisaspecialkindofintermediateoperation.It'sasocalledstatefuloperationsince

  • 4/18/2016 Java8StreamTutorialBenjaminWinterberg

    http://winterbe.com/posts/2014/07/31/java8streamtutorialexamples/ 8/27

    inordertosortacollectionofelementsyouhavetomaintainstateduringordering.

    Executingthisexampleresultsinthefollowingconsoleoutput:

    sort:a2;d2sort:b1;a2sort:b1;d2sort:b1;a2sort:b3;b1sort:b3;d2sort:c;b3sort:c;d2filter:a2map:a2forEach:A2filter:b1filter:b3filter:cfilter:d2

    First,thesortoperationisexecutedontheentireinputcollection.Inotherwords sorted is

    executedhorizontally.Sointhiscase sorted iscalledeighttimesformultiple

    combinationsoneveryelementintheinputcollection.

    Onceagainwecanoptimizetheperformancebyreorderingthechain:

    Stream.of("d2","a2","b1","b3","c").filter(s>{System.out.println("filter:"+s);returns.startsWith("a");}).sorted((s1,s2)>{System.out.printf("sort:%s;%s\n",s1,s2);returns1.compareTo(s2);}).map(s>{System.out.println("map:"+s);returns.toUpperCase();}).forEach(s>System.out.println("forEach:"+s));

    //filter:d2//filter:a2//filter:b1//filter:b3//filter:c//map:a2//forEach:A2

  • 4/18/2016 Java8StreamTutorialBenjaminWinterberg

    http://winterbe.com/posts/2014/07/31/java8streamtutorialexamples/ 9/27

    Inthisexample sorted isneverbeencalledbecause filter reducestheinputcollection

    tojustoneelement.Sotheperformanceisgreatlyincreasedforlargerinputcollections.

    ReusingStreams

    Java8streamscannotbereused.Assoonasyoucallanyterminaloperationthestreamis

    closed:

    Streamstream=Stream.of("d2","a2","b1","b3","c").filter(s>s.startsWith("a"));

    stream.anyMatch(s>true);//okstream.noneMatch(s>true);//exception

    Calling noneMatch after anyMatch onthesamestreamresultsinthefollowingexception:

    java.lang.IllegalStateException:streamhasalreadybeenoperateduponorclosedatjava.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:229)atjava.util.stream.ReferencePipeline.noneMatch(ReferencePipeline.java:459)atcom.winterbe.java8.Streams5.test7(Streams5.java:38)atcom.winterbe.java8.Streams5.main(Streams5.java:28)

    Toovercomethislimitationwehavetotocreateanewstreamchainforeveryterminal

    operationwewanttoexecute,e.g.wecouldcreateastreamsuppliertoconstructanew

    streamwithallintermediateoperationsalreadysetup:

    SupplierstreamSupplier=()>Stream.of("d2","a2","b1","b3","c").filter(s>s.startsWith("a"));

    streamSupplier.get().anyMatch(s>true);//okstreamSupplier.get().noneMatch(s>true);//ok

    Eachcallto get() constructsanewstreamonwhichwearesavetocallthedesired

    terminaloperation.

    AdvancedOperations

    Streamssupportplentyofdifferentoperations.We'vealreadylearnedaboutthemost

  • 4/18/2016 Java8StreamTutorialBenjaminWinterberg

    http://winterbe.com/posts/2014/07/31/java8streamtutorialexamples/ 10/27

    importantoperationslike filter or map .Ileaveituptoyoutodiscoverallotheravailable

    operations(seeStreamJavadoc).Insteadlet'sdivedeeperintothemorecomplex

    operations collect , flatMap and reduce .

    Mostcodesamplesfromthissectionusethefollowinglistofpersonsfordemonstration

    purposes:

    classPerson{Stringname;intage;

    Person(Stringname,intage){this.name=name;this.age=age;}

    @OverridepublicStringtoString(){returnname;}}

    Listpersons=Arrays.asList(newPerson("Max",18),newPerson("Peter",23),newPerson("Pamela",23),newPerson("David",12));

    Collect

    Collectisanextremelyusefulterminaloperationtotransformtheelementsofthestream

    intoadifferentkindofresult,e.g.a List , Set or Map .Collectacceptsa Collector

    whichconsistsoffourdifferentoperations:asupplier,anaccumulator,acombineranda

    finisher.Thissoundssupercomplicatedatfirst,butthegoodpartisJava8supports

    variousbuiltincollectorsviathe Collectors class.Soforthemostcommonoperations

    youdon'thavetoimplementacollectoryourself.

    Let'sstartwithaverycommonusecase:

    Listfiltered=persons.stream().filter(p>p.name.startsWith("P")).collect(Collectors.toList());

    http://docs.oracle.com/javase/8/docs/api/java/util/stream/Stream.html

  • 4/18/2016 Java8StreamTutorialBenjaminWinterberg

    http://winterbe.com/posts/2014/07/31/java8streamtutorialexamples/ 11/27

    System.out.println(filtered);//[Peter,Pamela]

    Asyoucanseeit'sverysimpletoconstructalistfromtheelementsofastream.Needa

    setinsteadoflistjustuse Collectors.toSet() .

    Thenextexamplegroupsallpersonsbyage:

    MappersonsByAge=persons.stream().collect(Collectors.groupingBy(p>p.age));

    personsByAge.forEach((age,p)>System.out.format("age%s:%s\n",age,p));

    //age18:[Max]//age23:[Peter,Pamela]//age12:[David]

    Collectorsareextremelyversatile.Youcanalsocreateaggregationsontheelementsof

    thestream,e.g.determiningtheaverageageofallpersons:

    DoubleaverageAge=persons.stream().collect(Collectors.averagingInt(p>p.age));

    System.out.println(averageAge);//19.0

    Ifyou'reinterestedinmorecomprehensivestatistics,thesummarizingcollectorsreturna

    specialbuiltinsummarystatisticsobject.Sowecansimplydeterminemin,maxand

    arithmeticaverageageofthepersonsaswellasthesumandcount.

    IntSummaryStatisticsageSummary=persons.stream().collect(Collectors.summarizingInt(p>p.age));

    System.out.println(ageSummary);//IntSummaryStatistics{count=4,sum=76,min=12,average=19.000000,max=23}

    Thenextexamplejoinsallpersonsintoasinglestring:

    Stringphrase=persons

  • 4/18/2016 Java8StreamTutorialBenjaminWinterberg

    http://winterbe.com/posts/2014/07/31/java8streamtutorialexamples/ 12/27

    .stream().filter(p>p.age>=18).map(p>p.name).collect(Collectors.joining("and","InGermany","areoflegalage."));

    System.out.println(phrase);//InGermanyMaxandPeterandPamelaareoflegalage.

    Thejoincollectoracceptsadelimiteraswellasanoptionalprefixandsuffix.

    Inordertotransformthestreamelementsintoamap,wehavetospecifyhowboththe

    keysandthevaluesshouldbemapped.Keepinmindthatthemappedkeysmustbe

    unique,otherwisean IllegalStateException isthrown.Youcanoptionallypassamerge

    functionasanadditionalparametertobypasstheexception:

    Mapmap=persons.stream().collect(Collectors.toMap(p>p.age,p>p.name,(name1,name2)>name1+";"+name2));

    System.out.println(map);//{18=Max,23=Peter;Pamela,12=David}

    Nowthatweknowsomeofthemostpowerfulbuiltincollectors,let'strytobuildourown

    specialcollector.Wewanttotransformallpersonsofthestreamintoasinglestring

    consistingofallnamesinupperlettersseparatedbythe | pipecharacter.Inorderto

    achievethiswecreateanewcollectorvia Collector.of() .Wehavetopassthefour

    ingredientsofacollector:asupplier,anaccumulator,acombinerandafinisher.

    CollectorpersonNameCollector=Collector.of(()>newStringJoiner("|"),//supplier(j,p)>j.add(p.name.toUpperCase()),//accumulator(j1,j2)>j1.merge(j2),//combinerStringJoiner::toString);//finisher

    Stringnames=persons.stream().collect(personNameCollector);

    System.out.println(names);//MAX|PETER|PAMELA|DAVID

  • 4/18/2016 Java8StreamTutorialBenjaminWinterberg

    http://winterbe.com/posts/2014/07/31/java8streamtutorialexamples/ 13/27

    SincestringsinJavaareimmutable,weneedahelperclasslike StringJoiner toletthe

    collectorconstructourstring.ThesupplierinitiallyconstructssuchaStringJoinerwiththe

    appropriatedelimiter.Theaccumulatorisusedtoaddeachpersonsuppercasednameto

    theStringJoiner.ThecombinerknowshowtomergetwoStringJoinersintoone.Inthelast

    stepthefinisherconstructsthedesiredStringfromtheStringJoiner.

    FlatMap

    We'vealreadylearnedhowtotransformtheobjectsofastreamintoanothertypeof

    objectsbyutilizingthe map operation.Mapiskindalimitedbecauseeveryobjectcanonly

    bemappedtoexactlyoneotherobject.Butwhatifwewanttotransformoneobjectinto

    multipleothersornoneatall?Thisiswhere flatMap comestotherescue.

    FlatMaptransformseachelementofthestreamintoastreamofotherobjects.Soeach

    objectwillbetransformedintozero,oneormultipleotherobjectsbackedbystreams.The

    contentsofthosestreamswillthenbeplacedintothereturnedstreamofthe flatMap

    operation.

    Beforewesee flatMap inactionweneedanappropriatetypehierarchy:

    classFoo{Stringname;Listbars=newArrayList();

    Foo(Stringname){this.name=name;}}

    classBar{Stringname;

    Bar(Stringname){this.name=name;}}

    Next,weutilizeourknowledgeaboutstreamstoinstantiateacoupleofobjects:

    Listfoos=newArrayList();

    //createfoosIntStream

  • 4/18/2016 Java8StreamTutorialBenjaminWinterberg

    http://winterbe.com/posts/2014/07/31/java8streamtutorialexamples/ 14/27

    .range(1,4).forEach(i>foos.add(newFoo("Foo"+i)));

    //createbarsfoos.forEach(f>IntStream.range(1,4).forEach(i>f.bars.add(newBar("Bar"+i+"

  • 4/18/2016 Java8StreamTutorialBenjaminWinterberg

    http://winterbe.com/posts/2014/07/31/java8streamtutorialexamples/ 15/27

    Thinkofahighlyhierarchicalstructurelikethis:

    classOuter{Nestednested;}

    classNested{Innerinner;}

    classInner{Stringfoo;}

    Inordertoresolvetheinnerstring foo ofanouterinstanceyouhavetoaddmultiplenull

    checkstopreventpossibleNullPointerExceptions:

    Outerouter=newOuter();if(outer!=null&&outer.nested!=null&&outer.nested.inner!=null){System.out.println(outer.nested.inner.foo);}

    Thesamebehaviorcanbeobtainedbyutilizingoptionals flatMap operation:

    Optional.of(newOuter()).flatMap(o>Optional.ofNullable(o.nested)).flatMap(n>Optional.ofNullable(n.inner)).flatMap(i>Optional.ofNullable(i.foo)).ifPresent(System.out::println);

    Eachcallto flatMap returnsan Optional wrappingthedesiredobjectifpresentor null

    ifabsent.

    Reduce

    Thereductionoperationcombinesallelementsofthestreamintoasingleresult.Java8

    supportsthreedifferentkindof reduce methods.Thefirstonereducesastreamof

    elementstoexactlyoneelementofthestream.Let'sseehowwecanusethismethodto

    determinetheoldestperson:

    persons.stream()

  • 4/18/2016 Java8StreamTutorialBenjaminWinterberg

    http://winterbe.com/posts/2014/07/31/java8streamtutorialexamples/ 16/27

    .reduce((p1,p2)>p1.age>p2.age?p1:p2).ifPresent(System.out::println);//Pamela

    The reduce methodacceptsa BinaryOperator accumulatorfunction.That'sactuallya

    BiFunction wherebothoperandssharethesametype,inthatcase Person .BiFunctions

    arelike Function butaccepttwoarguments.Theexamplefunctioncomparesboth

    personsagesinordertoreturnthepersonwiththemaximumage.

    Thesecond reduce methodacceptsbothanidentityvalueanda BinaryOperator

    accumulator.ThismethodcanbeutilizedtoconstructanewPersonwiththeaggregated

    namesandagesfromallotherpersonsinthestream:

    Personresult=persons.stream().reduce(newPerson("",0),(p1,p2)>{p1.age+=p2.age;p1.name+=p2.name;returnp1;});

    System.out.format("name=%s;age=%s",result.name,result.age);//name=MaxPeterPamelaDavid;age=76

    Thethird reduce methodacceptsthreeparameters:anidentityvalue,a BiFunction

    accumulatorandacombinerfunctionoftype BinaryOperator .Sincetheidentityvalues

    typeisnotrestrictedtothe Person type,wecanutilizethisreductiontodeterminethe

    sumofagesfromallpersons:

    IntegerageSum=persons.stream().reduce(0,(sum,p)>sum+=p.age,(sum1,sum2)>sum1+sum2);

    System.out.println(ageSum);//76

    Asyoucanseetheresultis76,butwhat'shappeningexactlyunderthehood?Let'sextend

    theabovecodebysomedebugoutput:

    IntegerageSum=persons.stream().reduce(0,(sum,p)>{System.out.format("accumulator:sum=%s;person=%s\n",sum,p);

  • 4/18/2016 Java8StreamTutorialBenjaminWinterberg

    http://winterbe.com/posts/2014/07/31/java8streamtutorialexamples/ 17/27

    returnsum+=p.age;},(sum1,sum2)>{System.out.format("combiner:sum1=%s;sum2=%s\n",sum1,sum2);returnsum1+sum2;});

    //accumulator:sum=0;person=Max//accumulator:sum=18;person=Peter//accumulator:sum=41;person=Pamela//accumulator:sum=64;person=David

    Asyoucanseetheaccumulatorfunctiondoesallthework.Itfirstgetcalledwiththeinitial

    identityvalue0andthefirstpersonMax.Inthenextthreesteps sum continuallyincreases

    bytheageofthelaststepspersonuptoatotalageof76.

    Waitwat?Thecombinernevergetscalled?Executingthesamestreaminparallelwilllift

    thesecret:

    IntegerageSum=persons.parallelStream().reduce(0,(sum,p)>{System.out.format("accumulator:sum=%s;person=%s\n",sum,p);returnsum+=p.age;},(sum1,sum2)>{System.out.format("combiner:sum1=%s;sum2=%s\n",sum1,sum2);returnsum1+sum2;});

    //accumulator:sum=0;person=Pamela//accumulator:sum=0;person=David//accumulator:sum=0;person=Max//accumulator:sum=0;person=Peter//combiner:sum1=18;sum2=23//combiner:sum1=23;sum2=12//combiner:sum1=41;sum2=35

    Executingthisstreaminparallelresultsinanentirelydifferentexecutionbehavior.Nowthe

    combinerisactuallycalled.Sincetheaccumulatoriscalledinparallel,thecombineris

    neededtosumuptheseparateaccumulatedvalues.

    Let'sdivedeeperintoparallelstreamsinthenextchapter.

    ParallelStreams

  • 4/18/2016 Java8StreamTutorialBenjaminWinterberg

    http://winterbe.com/posts/2014/07/31/java8streamtutorialexamples/ 18/27

    Streamscanbeexecutedinparalleltoincreaseruntimeperformanceonlargeamountof

    inputelements.Parallelstreamsuseacommon ForkJoinPool availableviathestatic

    ForkJoinPool.commonPool() method.Thesizeoftheunderlyingthreadpoolusesupto

    fivethreadsdependingontheamountofavailablephysicalCPUcores:

    ForkJoinPoolcommonPool=ForkJoinPool.commonPool();System.out.println(commonPool.getParallelism());//3

    Onmymachinethecommonpoolisinitializedwithaparallelismof3perdefault.This

    valuecanbedecreasedorincreasedbysettingthefollowingJVMparameter:

    Djava.util.concurrent.ForkJoinPool.common.parallelism=5

    Collectionssupportthemethod parallelStream() tocreateaparallelstreamofelements.

    Alternativelyyoucancalltheintermediatemethod parallel() onagivenstreamto

    convertasequentialstreamtoaparallelcounterpart.

    Inordertounderstatetheparallelexecutionbehaviorofaparallelstreamthenextexample

    printsinformationaboutthecurrentthreadto sout :

    Arrays.asList("a1","a2","b1","c2","c1").parallelStream().filter(s>{System.out.format("filter:%s[%s]\n",s,Thread.currentThread().getName());returntrue;}).map(s>{System.out.format("map:%s[%s]\n",s,Thread.currentThread().getName());returns.toUpperCase();}).forEach(s>System.out.format("forEach:%s[%s]\n",s,Thread.currentThread().getName()));

    Byinvestigatingthedebugoutputweshouldgetabetterunderstandingwhichthreadsare

    actuallyusedtoexecutethestreamoperations:

    filter:b1[main]filter:a2[ForkJoinPool.commonPoolworker1]map:a2[ForkJoinPool.commonPoolworker1]filter:c2[ForkJoinPool.commonPoolworker3]

  • 4/18/2016 Java8StreamTutorialBenjaminWinterberg

    http://winterbe.com/posts/2014/07/31/java8streamtutorialexamples/ 19/27

    map:c2[ForkJoinPool.commonPoolworker3]filter:c1[ForkJoinPool.commonPoolworker2]map:c1[ForkJoinPool.commonPoolworker2]forEach:C2[ForkJoinPool.commonPoolworker3]forEach:A2[ForkJoinPool.commonPoolworker1]map:b1[main]forEach:B1[main]filter:a1[ForkJoinPool.commonPoolworker3]map:a1[ForkJoinPool.commonPoolworker3]forEach:A1[ForkJoinPool.commonPoolworker3]forEach:C1[ForkJoinPool.commonPoolworker2]

    Asyoucanseetheparallelstreamutilizesallavailablethreadsfromthecommon

    ForkJoinPool forexecutingthestreamoperations.Theoutputmaydifferinconsecutive

    runsbecausethebehaviorwhichparticularthreadisactuallyusedisnondeterministic.

    Let'sextendtheexamplebyanadditionalstreamoperation, sort :

    Arrays.asList("a1","a2","b1","c2","c1").parallelStream().filter(s>{System.out.format("filter:%s[%s]\n",s,Thread.currentThread().getName());returntrue;}).map(s>{System.out.format("map:%s[%s]\n",s,Thread.currentThread().getName());returns.toUpperCase();}).sorted((s1,s2)>{System.out.format("sort:%s%s[%s]\n",s1,s2,Thread.currentThread().getName());returns1.compareTo(s2);}).forEach(s>System.out.format("forEach:%s[%s]\n",s,Thread.currentThread().getName()));

    Theresultmaylookstrangeatfirst:

    filter:c2[ForkJoinPool.commonPoolworker3]filter:c1[ForkJoinPool.commonPoolworker2]map:c1[ForkJoinPool.commonPoolworker2]filter:a2[ForkJoinPool.commonPoolworker1]map:a2[ForkJoinPool.commonPoolworker1]filter:b1[main]map:b1[main]filter:a1[ForkJoinPool.commonPoolworker2]

  • 4/18/2016 Java8StreamTutorialBenjaminWinterberg

    http://winterbe.com/posts/2014/07/31/java8streamtutorialexamples/ 20/27

    map:a1[ForkJoinPool.commonPoolworker2]map:c2[ForkJoinPool.commonPoolworker3]sort:A2A1[main]sort:B1A2[main]sort:C2B1[main]sort:C1C2[main]sort:C1B1[main]sort:C1C2[main]forEach:A1[ForkJoinPool.commonPoolworker1]forEach:C2[ForkJoinPool.commonPoolworker3]forEach:B1[main]forEach:A2[ForkJoinPool.commonPoolworker2]forEach:C1[ForkJoinPool.commonPoolworker1]

    Itseemsthat sort isexecutedsequentiallyonthemainthreadonly.Actually, sort ona

    parallelstreamusesthenewJava8method Arrays.parallelSort() underthehood.As

    statedinJavadocthismethoddecidesonthelengthofthearrayifsortingwillbe

    performedsequentiallyorinparallel:

    Ifthelengthofthespecifiedarrayislessthantheminimumgranularity,thenitis

    sortedusingtheappropriateArrays.sortmethod.

    Comingbacktothe reduce examplefromthelastsection.Wealreadyfoundoutthatthe

    combinerfunctionisonlycalledinparallelbutnotinsequentialstreams.Let'sseewhich

    threadsareactuallyinvolved:

    Listpersons=Arrays.asList(newPerson("Max",18),newPerson("Peter",23),newPerson("Pamela",23),newPerson("David",12));

    persons.parallelStream().reduce(0,(sum,p)>{System.out.format("accumulator:sum=%s;person=%s[%s]\n",sum,p,Thread.currentThread().getName());returnsum+=p.age;},(sum1,sum2)>{System.out.format("combiner:sum1=%s;sum2=%s[%s]\n",sum1,sum2,Thread.currentThread().getName());returnsum1+sum2;});

    https://docs.oracle.com/javase/8/docs/api/java/util/Arrays.html#parallelSort-T:A-

  • 4/18/2016 Java8StreamTutorialBenjaminWinterberg

    http://winterbe.com/posts/2014/07/31/java8streamtutorialexamples/ 21/27

    Theconsoleoutputrevealsthatboththeaccumulatorandthecombinerfunctionsare

    executedinparallelonallavailablethreads:

    accumulator:sum=0;person=Pamela;[main]accumulator:sum=0;person=Max;[ForkJoinPool.commonPoolworker3]accumulator:sum=0;person=David;[ForkJoinPool.commonPoolworker2]accumulator:sum=0;person=Peter;[ForkJoinPool.commonPoolworker1]combiner:sum1=18;sum2=23;[ForkJoinPool.commonPoolworker1]combiner:sum1=23;sum2=12;[ForkJoinPool.commonPoolworker2]combiner:sum1=41;sum2=35;[ForkJoinPool.commonPoolworker2]

    Insummary,itcanbestatedthatparallelstreamscanbringbeaniceperformanceboost

    tostreamswithalargeamountofinputelements.Butkeepinmindthatsomeparallel

    streamoperationslike reduce and collect needadditionalcomputations(combine

    operations)whichisn'tneededwhenexecutedsequentially.

    Furthermorewe'velearnedthatallparallelstreamoperationssharethesameJVMwide

    common ForkJoinPool .Soyouprobablywanttoavoidimplementingslowblocking

    streamoperationssincethatcouldpotentiallyslowdownotherpartsofyourapplication

    whichrelyheavilyonparallelstreams.

    That'sit

    MyprogrammingguidetoJava8streamsendshere.Ifyou'reinterestedinlearningmore

    aboutJava8streams,IrecommendtoyoutheStreamJavadocpackagedocumentation.If

    youwanttolearnmoreabouttheunderlyingmechanisms,youprobablywanttoread

    MartinFowlersarticleaboutCollectionPipelines.

    Ifyou'reinterestedinJavaScriptaswell,youmaywanttohavealookatStream.jsa

    JavaScriptimplementationoftheJava8StreamsAPI.YoumayalsowannareadmyJava

    8TutorialandmyJava8NashornTutorial.

    Hopefullythistutorialwashelpfultoyouandyou'veenjoyedreadingit.Thefullsource

    codeofthetutorialsamplesishostedonGitHub.Feelfreetoforktherepositoryorsend

    meyourfeedbackviaTwitter.

    Happycoding!

    http://docs.oracle.com/javase/8/docs/api/java/util/stream/package-summary.html#NonInterferencehttp://martinfowler.com/articles/collection-pipeline/https://github.com/winterbe/streamjshttp://winterbe.com/posts/2014/03/16/java-8-tutorial/http://winterbe.com/posts/2014/04/05/java8-nashorn-tutorial/https://github.com/winterbe/java8-tutorialhttps://github.com/winterbe/java8-tutorial/forkhttps://twitter.com/winterbe_

  • 4/18/2016 Java8StreamTutorialBenjaminWinterberg

    http://winterbe.com/posts/2014/07/31/java8streamtutorialexamples/ 22/27

    [email protected] [email protected]_

    Tweet

    ReadMore

    BenjaminisSoftwareEngineer,FullStackDeveloperatPondus,anexcited

    runnerandtablefoosballplayer.GetintouchonTwitter,Google+andGitHub.

    Recent AllPosts Java Tutorials

    IntegratingReact.jsintoExistingjQueryWebApplications

    Java8ConcurrencyTutorial:AtomicVariablesandConcurrentMap

    Java8ConcurrencyTutorial:SynchronizationandLocks

    Java8ConcurrencyTutorial:ThreadsandExecutors

    24Comments winterbe.com Login1

    Share SortbyBest

    Jointhediscussion

    Reply

    TomasGradin ayearago"Sotheperformanceisgreatlyreducedforlargerinputcollections."

    Ithinkyoumeanincreased?:)

    2

    Recommend 16

    Share

    https://github.com/winterbehttps://twitter.com/intent/follow?original_referer=http%3A%2F%2Fwinterbe.com%2Fposts%2F2014%2F07%2F31%2Fjava8-stream-tutorial-examples%2F&ref_src=twsrc%5Etfw&region=follow_link&screen_name=winterbe_&tw_p=followbuttonhttps://twitter.com/intent/tweet?original_referer=http%3A%2F%2Fwinterbe.com%2Fposts%2F2014%2F07%2F31%2Fjava8-stream-tutorial-examples%2F&ref_src=twsrc%5Etfw&text=Java%208%20Stream%20Tutorial%20-%20Benjamin%20Winterberg&tw_p=tweetbutton&url=http%3A%2F%2Fwinterbe.com%2Fposts%2F2014%2F07%2F31%2Fjava8-stream-tutorial-examples%2F&via=winterbe_http://pondus.de/en/homepage/https://twitter.com/winterbe_https://plus.google.com/105973259367211176218/postshttps://github.com/winterbehttp://winterbe.com/blog/http://winterbe.com/java/http://winterbe.com/tutorials/http://winterbe.com/posts/2015/08/24/integrate-reactjs-into-jquery-webapps/http://winterbe.com/posts/2015/05/22/java8-concurrency-tutorial-atomic-concurrent-map-examples/http://winterbe.com/posts/2015/04/30/java8-concurrency-tutorial-synchronized-locks-examples/http://winterbe.com/posts/2015/04/07/java8-concurrency-tutorial-thread-executor-examples/https://disqus.com/home/forums/winterbe/https://disqus.com/home/inbox/https://disqus.com/by/tgradin/http://winterbe.com/posts/2014/07/31/java8-stream-tutorial-examples/#comment-1988157343https://disqus.com/by/tgradin/

  • 4/18/2016 Java8StreamTutorialBenjaminWinterberg

    http://winterbe.com/posts/2014/07/31/java8streamtutorialexamples/ 23/27

    Reply

    BenjaminWinterberg ayearagoMod >TomasGradinFixedthat,thanks!:)

    Reply

    RainerSchamm ayearagoGreatpost.IwasjustwonderingaboutwhatyousaidaboutArrays.parallelSort():

    "...thecomparatorisexecutedsolelyonthemainthreadbuttheactualsortingalgorithmisexecutedinparallel..."

    IdidsomemorereadingandsometestsandIthinkyourarrayissimplytosmallfortheparallelsortingtokickinproperly.

    Ifyouincreasethesizeabityouwillseethatthecomparatorsalsorunindifferentthreads.

    Reference:

    http://stackoverflow.com/quest...

    ...

    ThemethodusesathresholdvalueandanyarrayofsizelesserthanthethresholdvalueissortedusingtheArrays#sort()API(i.esequentialsorting).Andthethresholdiscalculatedconsideringtheparallelismofthemachine,sizeofthearrayandiscalculatedas...

    1

    Reply

    BenjaminWinterberg ayearagoMod >RainerSchammYou'reabsolutelyright.I'vefixedthesectionaccordingly.Thanksforpointingthatout!

    Reply

    Erol amonthagothankyouBenjaminforthisgreatpost..It'saveryusefulrepository.

    Reply

    HseyinBarn 2monthsagoThisisthebestpostaboutthestreams.Thanks.

    JohnstonPowers 2monthsagoThanksforthenicetutorial.Iwastotallyconfusedbywhatwasgoingoninthelastexampleofreducewithaparallelstreamandwhatthedifferencein"accumulating"and"combining"thingsisi.e.persons.parallelStream().reduce(identity,accumulator,combiner)untilIplayedaroundwithchangingtheaccumulatorfunctiontonotdoanythingbutreturntheageoftheperson.

    Share

    Share

    Share

    Share

    Share

    https://disqus.com/by/winterbe/http://winterbe.com/posts/2014/07/31/java8-stream-tutorial-examples/#comment-1998995788http://winterbe.com/posts/2014/07/31/java8-stream-tutorial-examples/#comment-1988157343https://disqus.com/by/rschamm/http://winterbe.com/posts/2014/07/31/java8-stream-tutorial-examples/#comment-1997972956http://stackoverflow.com/questions/17328077/difference-between-arrays-sort-and-arrays-parallelsorthttps://disqus.com/by/winterbe/http://winterbe.com/posts/2014/07/31/java8-stream-tutorial-examples/#comment-1998994843http://winterbe.com/posts/2014/07/31/java8-stream-tutorial-examples/#comment-1997972956https://disqus.com/by/disqus_PW7rEZgxc5/http://winterbe.com/posts/2014/07/31/java8-stream-tutorial-examples/#comment-2549356311https://disqus.com/by/h_seyin_bar_n/http://winterbe.com/posts/2014/07/31/java8-stream-tutorial-examples/#comment-2547221877https://disqus.com/by/johnstonpowers/http://winterbe.com/posts/2014/07/31/java8-stream-tutorial-examples/#comment-2508746853https://disqus.com/by/winterbe/https://disqus.com/by/rschamm/https://disqus.com/by/winterbe/https://disqus.com/by/disqus_PW7rEZgxc5/https://disqus.com/by/h_seyin_bar_n/https://disqus.com/by/johnstonpowers/

  • 4/18/2016 Java8StreamTutorialBenjaminWinterberg

    http://winterbe.com/posts/2014/07/31/java8streamtutorialexamples/ 24/27

    Reply

    theageoftheperson.

    Maybethatwasobvioustoothersbuttheaccumulatorwhenitrunsinparalleldoesn'tdoanythingotherthanreturnanintegerintoahiddencollectionofintegersforthecombinerfunctiontofinallyoperateon.IguessI'mstillnotentirelysurewhat'sgoingonunderthehoodbutapparentlyitcreatesthelistofages[18,23,23,12]fromtheaccumulatorandthenstartsrunningthecombinefunctiononthempairwise,18+23andthen23+12,storingeachvaluesomewhereandthencombinesthetwovaluesonelasttimetoget76.Isthisaproperunderstanding?

    p.s.thenamesofallthesestreammethodsandfunctioninterfacesseemreallyunintuitivebutmaybethat'sjustmylackofexperience.

    Reply

    AndersStorsveen 3monthsagoNicetutorial!ItwouldbenicetomentionthatanyMatchisashortcuttingterminaloperationthough.Wasn'tclearwhyitwouldstopprocessingafterthat.

    Reply

    harshitrastogi 3monthsagoGreatArticle,learnedquiteafewmorethingswhichiwasn'tawareofinjava8streams

    Reply

    xtint 4monthsagoAwesomepost!Thanks!

    Reply

    SuvenduMohanty 4monthsagoGreatPost..IgotaclearideaonStream.

    WiktorWandachowicz 5monthsagoIwasrecentlysurprisedbybehaviorofIntStreamregardingcollect()operation.Itriedtousethestreamas:

    ListsearchInRange(int[]tab,intmin,intmax){Listlist=Arrays.stream(tab).filter(i>(i>=min&&i

  • 4/18/2016 Java8StreamTutorialBenjaminWinterberg

    http://winterbe.com/posts/2014/07/31/java8streamtutorialexamples/ 25/27

    Reply

    seemore

    EventuallyIfoundthatinserting".boxed()"operationallowedmetocorrectlycall:collect(Collectors.toList())

    Reply

    RichardLyders 6monthsagoNote:igatherthatinsteadof"Inordertounderstatetheparallel"youmeant"Inordertounderscoretheparallel"...

    Reply

    RichardLyders 6monthsagoNicewalkthrough.

    Onetip:boththeFooandBarclassesrequire"Stringname"tobe"publicStringname"inorderfor"name"tobeavailablevia"f.name"and"b.name"inthefollow"FlatMap"examplecode.

    Goodwork.

    Reply

    DukeNuke'em 5monthsago>RichardLydersDoesntthatbreakencapsulation?

    Reply

    bokanist 6monthsagoThankyou!:)

    b3lun 7monthsago(inregardtocustomCollector)whatalmosteverybloggerouttherefails/omitstoexplainishowthedamnCollectorworksandhowtoactuallydoanewone:youneedanewclassthatismutablethisnewclasscontainsBOTHthestuffthatmutatesandtheendresult,thecollectiontoprocess(theendresultcanbethestuffthatmutates,asaspecialusecase)thesuppliercreatesthisnewclasstheaccumulatorreceivesthenewclassandanelementfromtheoriginalcollection(ithastoaddthereceivedelementtoitsinternallistaftercalculatingthingsbasedonstuffthatmutatesthestuffthatmutatescanmutateatthispoint,duuh,basedonwhatnewelementfromtheoriginalcollectionwasreceivedorbasedjustonitspreviousvalue)"accumulator"isafunctionalterm,notoneOOone(itismisleadingasitalsocontainingtheendresult,notjustthemutablestate)thecombinerisusedonlyduringparallelprocessing(whentheoriginalcollectionismeanttobeprocessedinparallel)willnotbecalledmostoftheusecasesithastojoin2instancesofthenewclassestogetherthefinisherhastoextractandreturntheoutputfromthenewclass

    forexample:ifihaveacollectionofsomeobjectsandiwantedtoupdateeachelement

    Share

    Share

    Share

    Share

    Share

    https://disqus.com/by/richard_lyders/http://winterbe.com/posts/2014/07/31/java8-stream-tutorial-examples/#comment-2310784184https://disqus.com/by/richard_lyders/http://winterbe.com/posts/2014/07/31/java8-stream-tutorial-examples/#comment-2310710762http://f.name/http://b.name/https://disqus.com/by/disqus_Zlik9rsWoA/http://winterbe.com/posts/2014/07/31/java8-stream-tutorial-examples/#comment-2358289997http://winterbe.com/posts/2014/07/31/java8-stream-tutorial-examples/#comment-2310710762https://disqus.com/by/bokanist/http://winterbe.com/posts/2014/07/31/java8-stream-tutorial-examples/#comment-2290486888https://disqus.com/by/b3lun/http://winterbe.com/posts/2014/07/31/java8-stream-tutorial-examples/#comment-2271223237https://disqus.com/by/richard_lyders/https://disqus.com/by/richard_lyders/https://disqus.com/by/disqus_Zlik9rsWoA/https://disqus.com/by/bokanist/https://disqus.com/by/b3lun/

  • 4/18/2016 Java8StreamTutorialBenjaminWinterberg

    http://winterbe.com/posts/2014/07/31/java8streamtutorialexamples/ 26/27

    Java8NashornTutorialBenjaminWinterberg19commentsayearago

    RyanHiDan,Iresolvedthisclasspath

    IntegratingReact.jsintoTraditionaljQueryWebapps1comment8monthsago

    TylerAndersenSoyoucreatedyour

    ALSOONWINTERBE.COM

    Reply

    seemore

    forexample:ifihaveacollectionofsomeobjectsandiwantedtoupdateeachelement

    Reply

    JirkaKremser 8monthsagoThanksforthepost.Justanote:it'sbettertousejust+insteadof+=inthisstatement:(it'sclosertothepurefunctionalstyle)

    p1.age+p2.agep1.name+p2.name

    Reply

    DhafirMoussa ayearagoThankyouforawellwrittentutorial.

    Reply

    AshwinJayaprakash ayearagoThisisthebestLambda/StreamtutorialI'veseensofar.Thanks!

    Reply

    BalzsBakai ayearagoGreat!Thanks.

    Reply

    JawaharElango ayearagoThisisanawesometutorialtostartwithjava8Streams..Thankyousomuch.

    Reply

    CoryTodd ayearagoThiswasgreatarticletostartthemorningwith.Haveyoudoneanyanalysisonthebreakeventhreshold(datainputsize)betweensequentialandparallelstreamoperations?Iwouldimaginethiswoulddependheavilyonthetypeofdatabutevenatopicalapproachinthesameformatusedinthispostwouldbeaninterestingread.

    Reply

    BenjaminWinterberg ayearagoMod >CoryToddThat'saninterestingquestion.MaybeI'lldofurtherinvestigationintothatlater.ThanksforyourFeedback.Pleaseletmeknowifyoufindanyarticlesonthat.

    Share

    Share

    Share

    Share

    Share

    Share

    Share

    Share

    http://disq.us/url?url=http%3A%2F%2Fwinterbe.com%2Fposts%2F2014%2F04%2F05%2Fjava8-nashorn-tutorial%2F%3A7vMtRCEkU6yBtK_gmugd-r9aMm0&imp=rfk39o3f1bqqg&prev_imp&forum_id=3523330&forum=winterbe&thread_id=3618744228&thread=3618754778&zone=thread&area=bottom&object_type=thread&object_id=3618754778http://disq.us/url?url=http%3A%2F%2Fwinterbe.com%2Fposts%2F2014%2F04%2F05%2Fjava8-nashorn-tutorial%2F%3A7vMtRCEkU6yBtK_gmugd-r9aMm0&imp=rfk39o3f1bqqg&prev_imp&forum_id=3523330&forum=winterbe&thread_id=3618744228&thread=3618754778&zone=thread&area=bottom&object_type=thread&object_id=3618754778http://disq.us/url?url=http%3A%2F%2Fwinterbe.com%2Fposts%2F2015%2F08%2F24%2Fintegrate-reactjs-into-jquery-webapps%2F%3AIPDIpC69NOibKNMrptt57B96mCY&imp=rfk39o3f1bqqg&prev_imp&forum_id=3523330&forum=winterbe&thread_id=3618744228&thread=4060978183&zone=thread&area=bottom&object_type=thread&object_id=4060978183http://disq.us/url?url=http%3A%2F%2Fwinterbe.com%2Fposts%2F2015%2F08%2F24%2Fintegrate-reactjs-into-jquery-webapps%2F%3AIPDIpC69NOibKNMrptt57B96mCY&imp=rfk39o3f1bqqg&prev_imp&forum_id=3523330&forum=winterbe&thread_id=3618744228&thread=4060978183&zone=thread&area=bottom&object_type=thread&object_id=4060978183https://disqus.com/by/jkremser/http://winterbe.com/posts/2014/07/31/java8-stream-tutorial-examples/#comment-2192080439http://p1.name/http://p2.name/https://disqus.com/by/dhafirmoussa/http://winterbe.com/posts/2014/07/31/java8-stream-tutorial-examples/#comment-2036288718https://disqus.com/by/AshwinJay/http://winterbe.com/posts/2014/07/31/java8-stream-tutorial-examples/#comment-2033012077https://disqus.com/by/balzsbakai/http://winterbe.com/posts/2014/07/31/java8-stream-tutorial-examples/#comment-1978044237https://disqus.com/by/jawaharelango/http://winterbe.com/posts/2014/07/31/java8-stream-tutorial-examples/#comment-1972356476https://disqus.com/by/ptidevelopers/http://winterbe.com/posts/2014/07/31/java8-stream-tutorial-examples/#comment-1923507837https://disqus.com/by/winterbe/http://winterbe.com/posts/2014/07/31/java8-stream-tutorial-examples/#comment-1924843869http://winterbe.com/posts/2014/07/31/java8-stream-tutorial-examples/#comment-1923507837https://disqus.com/by/jkremser/https://disqus.com/by/dhafirmoussa/https://disqus.com/by/AshwinJay/https://disqus.com/by/balzsbakai/https://disqus.com/by/jawaharelango/https://disqus.com/by/ptidevelopers/https://disqus.com/by/winterbe/

  • 4/18/2016 Java8StreamTutorialBenjaminWinterberg

    http://winterbe.com/posts/2014/07/31/java8streamtutorialexamples/ 27/27

    20092015BenjaminWinterberg

    RyanHiDan,Iresolvedthisclasspathissueby.ScriptEngineengine=new

    TylerAndersenSoyoucreatedyourownReactContentRendererwrapperfunctionaroundReact'snativerenderfunction

    5TipsforCustomizingEclipseBenjaminWinterberg1commentayearago

    SaisuryaKattamuriHeyBenjaminwhichcolorthemeyouhaveusedforjava8tutorialcodesnippets,Itriedsearchingbut

    Java8ConcurrencyTutorial:ThreadsandExecutors9commentsayearago

    ftudoneIsuggesthavingalookQuasarandtheParallelUniversestackaswell:http://www.paralleluniverse.co...Quasar

    http://disq.us/url?url=http%3A%2F%2Fwinterbe.com%2Fposts%2F2014%2F04%2F05%2Fjava8-nashorn-tutorial%2F%3A7vMtRCEkU6yBtK_gmugd-r9aMm0&imp=rfk39o3f1bqqg&prev_imp&forum_id=3523330&forum=winterbe&thread_id=3618744228&thread=3618754778&zone=thread&area=bottom&object_type=thread&object_id=3618754778http://disq.us/url?url=http%3A%2F%2Fwinterbe.com%2Fposts%2F2015%2F08%2F24%2Fintegrate-reactjs-into-jquery-webapps%2F%3AIPDIpC69NOibKNMrptt57B96mCY&imp=rfk39o3f1bqqg&prev_imp&forum_id=3523330&forum=winterbe&thread_id=3618744228&thread=4060978183&zone=thread&area=bottom&object_type=thread&object_id=4060978183http://disq.us/url?url=http%3A%2F%2Fwinterbe.com%2Fposts%2F2009%2F09%2F25%2Fcustomizing-eclipse%2F%3AvMOyIKdGsrp67tI3hzEDT6R0F-M&imp=rfk39o3f1bqqg&prev_imp&forum_id=3523330&forum=winterbe&thread_id=3618744228&thread=3622382289&zone=thread&area=bottom&object_type=thread&object_id=3622382289http://disq.us/url?url=http%3A%2F%2Fwinterbe.com%2Fposts%2F2009%2F09%2F25%2Fcustomizing-eclipse%2F%3AvMOyIKdGsrp67tI3hzEDT6R0F-M&imp=rfk39o3f1bqqg&prev_imp&forum_id=3523330&forum=winterbe&thread_id=3618744228&thread=3622382289&zone=thread&area=bottom&object_type=thread&object_id=3622382289http://disq.us/url?url=http%3A%2F%2Fwinterbe.com%2Fposts%2F2015%2F04%2F07%2Fjava8-concurrency-tutorial-thread-executor-examples%2F%3AFmYPYWd2KGo67JA29nhKPhPvXuM&imp=rfk39o3f1bqqg&prev_imp&forum_id=3523330&forum=winterbe&thread_id=3618744228&thread=3660859947&zone=thread&area=bottom&object_type=thread&object_id=3660859947http://disq.us/url?url=http%3A%2F%2Fwinterbe.com%2Fposts%2F2015%2F04%2F07%2Fjava8-concurrency-tutorial-thread-executor-examples%2F%3AFmYPYWd2KGo67JA29nhKPhPvXuM&imp=rfk39o3f1bqqg&prev_imp&forum_id=3523330&forum=winterbe&thread_id=3618744228&thread=3660859947&zone=thread&area=bottom&object_type=thread&object_id=3660859947