IntStream concat() method creates a concatenated stream in which the elements are all the elements of the first stream followed by all the elements of the second stream. The resulting stream is ordered if both of the input streams are ordered, and parallel if either of the input streams is parallel.
static IntStream concat(IntStream a, IntStream b) Where, IntStream is a sequence of primitive int-valued elements, a represents the first stream, b represents the second stream and the function returns the concatenation of the two input IntStreams.
The calls to IntStream.concat(IntStream a, IntStream b) can be think of as forming a binary tree. The concatenation of all the input streams is at the root. The individual input streams are at the leaves. Below given is example for 3 IntStreams a, b and c.
Each additional input stream adds one layer of depth to the tree and one layer of indirection to reach all the other streams.
Note : The elements returned by IntStream.concat() method is ordered. For example, the following two lines returns the same result:
IntStream.concat(IntStream.concat(stream1, stream2), stream3); IntStream.concat(stream1, IntStream.concat(stream2, stream3));
But the result for the following two are different.
IntStream.concat(IntStream.concat(stream1, stream2), stream3); IntStream.concat(IntStream.concat(stream2, stream1), stream3);
Example 1 :
2 4 6 1 3 5
Example 2 :
2 4 6 1
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- DoubleStream concat() in Java
- Stream.concat() in Java
- LongStream concat() in Java
- Java String concat() with examples
- Difference between concat() and + operator in Java
- IntStream sum() in Java
- IntStream of() in Java
- Ints concat() function | Guava | Java
- IntStream parallel() in Java
- IntStream boxed() in Java
- IntStream mapToObj() in Java
- IntStream builder() in Java
- IntStream max() in Java with examples
- IntStream asLongStream() in Java
- IntStream mapToLong() in Java
- IntStream limit() in Java
- IntStream min() in Java with Examples
- IntStream iterator() in Java
- IntStream rangeClosed() in Java
- IntStream range() in Java
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.