DoubleStream concat() method in Java


The concat() method of the DoubleStream class creates a stream which is concatenated. The elements of the resultant stream are all the elements of the first stream followed by all the elements of the second stream.

The syntax is as follows.

static DoubleStream concat(DoubleStream streamOne, DoubleStream streamTwo)

Here, streamOne is the first stream whereas streamTwo is the second stream.

To use the DoubleStream class in Java, import the following package.

import java.util.stream.DoubleStream;

Create a DoubleStream with some elements.

DoubleStream doubleStream1 = DoubleStream.of(20.5, 30.6, 58.9, 66.7);

Create another DoubleStream.

DoubleStream doubleStream2 = DoubleStream.of(71.8, 77.9, 82.3, 91.6, 98.4);

Now, concat the streams

DoubleStream.concat(doubleStream1, doubleStream2)

The following is an example to implement DoubleStream concat() method in Java.

Example

 Live Demo

import java.util.stream.DoubleStream;
import java.util.stream.Stream;
public class Demo {
   public static void main(String[] args) {
      DoubleStream doubleStream1 = DoubleStream.of(20.5, 30.6, 58.9, 66.7);
      DoubleStream doubleStream2 = DoubleStream.of(71.8, 77.9, 82.3, 91.6, 98.4);
      System.out.println("Concatenated Stream...");
      DoubleStream.concat(doubleStream1, doubleStream2).forEach(a -> System.out.println(a));
   }
}

Output

Concatenated Stream...
20.5
30.6
58.9
66.7
71.8
77.9
82.3
91.6
98.4

Updated on: 30-Jul-2019

75 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements