IntStream concat() in Java Last Updated : 06 Dec, 2018 Comments Improve Suggest changes Like Article Like Report 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. Syntax : 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 : Java // Implementation of IntStream.concat() // method in Java 8 with 2 IntStreams import java.util.*; import java.util.stream.IntStream; import java.util.stream.Stream; class GFG { // Driver code public static void main(String[] args) { // Creating two IntStreams IntStream stream1 = IntStream.of(2, 4, 6); IntStream stream2 = IntStream.of(1, 3, 5); // concatenating both the Streams // with IntStream.concat() function // and displaying the result IntStream.concat(stream1, stream2) .forEach(element -> System.out.println(element)); } } Output: 2 4 6 1 3 5 Example 2 : Java // Implementation of IntStream.concat() // method in Java 8 with 2 IntStreams import java.util.*; import java.util.stream.IntStream; import java.util.stream.Stream; class GFG { // Driver code public static void main(String[] args) { // Creating two IntStreams IntStream stream1 = IntStream.of(2, 4, 6); IntStream stream2 = IntStream.of(1, 2, 4); // concatenating both the Streams // with IntStream.concat() function // and displaying distinct elements // in the concatenated IntStream IntStream.concat(stream1, stream2).distinct(). forEach(element -> System.out.println(element)); } } Output: 2 4 6 1 Comment More infoAdvertise with us Next Article IntStream concat() in Java S Sahil_Bansall Follow Improve Article Tags : Misc Java Java - util package Java-Functions java-stream java-intstream +2 More Practice Tags : JavaMisc Similar Reads IntStream boxed() in Java IntStream boxed() returns a Stream consisting of the elements of this stream, each boxed to an Integer. Note : IntStream boxed() is a intermediate operation. These operations are always lazy. Intermediate operations are invoked on a Stream instance and after they finish their processing, they give a 2 min read Stream.concat() in Java Stream.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. Sy 4 min read Ints concat() function | Guava | Java Guava's Ints.concat() method is used to combine the arrays passed as parameters into a single array. This method returns the values from each provided array combined into a single array. For example, concat(new int[] {a, b}, new int[] {}, new int[] {c} returns the array {a, b, c}. Syntax: public sta 2 min read IntStream mapToObj() in Java IntStream mapToObj() returns an object-valued Stream consisting of the results of applying the given function. Note : IntStream mapToObj() is a intermediate operation. These operations are always lazy. Intermediate operations are invoked on a Stream instance and after they finish their processing, t 2 min read Program to convert IntStream to String in Java Given a Instream containing ASCII values, the task is to convert this Instream into a String containing the characters corresponding to the ASCII values. Examples: Input: IntStream = 71, 101, 101, 107, 115 Output: Geeks Input: IntStream = 71, 101, 101, 107, 115, 70, 111, 114, 71, 101, 101, 107, 115 1 min read Guava's Ints.join() Function in Java Ints.join() function provided by Guava library in Java for working with primitive integer arrays. It simplifies the process of converting an array of integers into a single concatenated string, with a specified delimiter separating the elements. For example, join("-", 1, 2, 3) returns the string "1- 2 min read RxJava Operator - Concat and Merge RxJava is the most significant library, and it is widely used by Android developers. It simplifies our lives. RxJava is used for multithreading, managing background processes, and eliminating callback hells. RxJava allows us to address a wide range of complicated use-cases. It allows us to accomplis 3 min read Java.io.Printstream Class in Java | Set 1 A PrintStream adds functionality to another output stream, namely the ability to print representations of various data values conveniently. Unlike other output streams, a PrintStream never throws an IOException; instead, exceptional situations merely set an internal flag that can be tested via the c 5 min read Integer toString() in Java The java.lang.Integer.toString() is an inbuilt method in Java which is used to return the String object representing this Integer's value. Syntax : public static String toString() Parameters: The method does not accept any parameters. Return Value:The method returns the string object of the particul 5 min read Difference between concat() and + operator in Java Strings are defined as an array of characters. The difference between a character array and a string is the string is terminated with a special character â\0â. Since arrays are immutable(cannot grow), Strings are immutable as well. Whenever a change to a String is made, an entirely new String is cre 6 min read Like