Java Streams - LongStream concat(LongStream a, LongStream b) example








LongStream concat(LongStream a, LongStream b) concatenates streams.

Syntax

concat has the following syntax.

static LongStream concat(LongStream a,   LongStream b)

Example

The following example shows how to use concat.

import java.util.stream.LongStream;

public class Main {
  public static void main(String[] args) {
    LongStream b = LongStream.concat(LongStream.rangeClosed(1L, 5L),LongStream.rangeClosed(1L, 6L));

    b.forEach(System.out::println);
  }
}

The code above generates the following result.