
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
LongStream concat Method in Java
The concat() method in the LongStream class creates a concatenated stream whose elements are all the elements of the first stream followed by all the elements of the second stream.
The syntax is as follows.
static LongStream concat(LongStream one, LongStream two)
Here, parameter one is the 1st stream, whereas two is the 2nd stream. The method returns the concatenation of both the streams.
To use the LongStream class in Java, import the following package.
import java.util.stream.LongStream;
Create a LongStrem and add some elements.
LongStream streamOne = LongStream.of(100L, 150L, 300L, 500L);
Now, create another stream.
LongStream streamTwo = LongStream.of(200L, 250L, 400L, 600L, 550L);
To concatenate both the above streams, use the concat() method.
LongStream.concat(streamOne, streamTwo)
The following is an example to implement LongStream concat() method in Java.
Example
import java.util.stream.LongStream; import java.util.stream.Stream; public class Demo { public static void main(String[] args) { LongStream streamOne = LongStream.of(100L, 150L, 300L, 500L); LongStream streamTwo = LongStream.of(200L, 250L, 400L, 600L, 550L); System.out.println("Result of the Concatenated Streams..."); LongStream.concat(streamOne, streamTwo).forEach(a -> System.out.println(a)); } }
Output
Result of the Concatenated Streams... 100 150 300 500 200 250 400 600 550
Advertisements