
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
IntStream concat Method in Java
The concat() method in the Java IntStream class forms a concatenated stream. The elements of this stream are all the elements of the first stream followed by all the elements of the second stream.
The syntax is as follows −
static IntStream concat(IntStream one, IntStream two)
Here, the parameter one is the first stream, whereas two is the second stream. The method returns the concatenated result of the stream one and two.
Let us create two IntStream and add some elements −
IntStream intStream1 = IntStream.of(10, 20, 30, 40, 50); IntStream intStream2 = IntStream.of(60, 70, 80, 90);
Now, to concate both the streams, use the concat() method −
IntStream.concat(intStream1, intStream2)
The following is an example to implement IntStream concat() method in Java −
Example
import java.util.stream.IntStream; import java.util.stream.Stream; public class Demo { public static void main(String[] args) { IntStream intStream1 = IntStream.of(10, 20, 30, 40, 50); IntStream intStream2 = IntStream.of(60, 70, 80, 90); // Concatenated stream System.out.println("Concatenated Stream..."); IntStream.concat(intStream1, intStream2).forEach(element -> System.out.println(element)); } }
Output
Concatenated Stream... 10 20 30 40 50 60 70 80 90
Advertisements