Efficient multiple-stream concatenation in Java
TechEmpower
OCTOBER 19, 2016
I want to combine the elements of multiple Stream instances into a single Stream. What's the best way to do this? This article compares a few different solutions. Stream.concat(a, b). The JDK provides Stream.concat(a, b) for concatenating two streams. void exampleConcatTwo () {. Stream a = Stream. of ( "one" , "two" ); Stream b = Stream. of ( "three" , "four" ); Stream out = Stream. concat ( a , b ); out. forEach ( System. out :: println ); // Output: // one. // two. // three. // four. }.
Let's personalize your content