

ResultStream.forEach(System.out::println) Output Here, resultStream contains all elements of odd followed by elements of even Stream resultStream = Stream.of(odd, even) // Stream.of() accept one or more list as a argument
#Multi counter on stream how to#
See the following example for how to merge two collections using the flatMap() method. The flatMap() applies the given mapping function to each element of collection stream and returns a new Stream of result elements of applied given mapping function. Stream finalStream = ncat(firstStream, armstrongNo.stream()) //Merge fisrtStream and stream of armstrongNoįinalStream.forEach(System.out::println) Output 1 //odd list elementsģ71 Example 2: Using the Stream.flatMap() Method Stream firstStream = ncat(odd.stream(), even.stream()) //Merge stream of odd and even list See the following example for how to combine a stream of three list using two times concat() method. If you want to combine/merge more than two list, need to call concat() method one time less than a number of lists. ResultStream.forEach(System.out::println) Output 1 //odd list elements

Stream resultStream = ncat(odd.stream(), even.stream()) //Concatenate stream of odd with stream of even Let’s see example for how to combine two integer type list stream into new one integer type stream list using the concat() method. ncat() is a static method, it combines two given streams into one logical stream of all elements of the first list followed by all elements of the second list. So, this article is going to show you how to get Java Stream of Multiple Lists using Java 8 Stream API (Stream interface) with an example. But what if we want a stream of two List or stream of List of Lists as a single logical stream to combine/merge those lists as one or do the same process on all. In Java 8, we know how to get a stream of List using stream() or parrallelStream() method of Collection interface. Example 2: Using the Stream.flatMap() Method.
