Close

Java 8 Streams - IntStream.concat Examples

Java 8 Streams Java Java API 


Interface:

java.util.stream.IntStream

java.lang.AutoCloseableAutoCloseablejava.util.stream.BaseStreamBaseStreamjava.util.stream.IntStreamIntStreamLogicBig

Method:

static IntStream concat(IntStream a, IntStream b)

Creates a lazily concatenated stream whose 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. When the resulting stream is closed, the close handlers for both input streams are invoked.

Examples


package com.logicbig.example.intstream;

import java.util.IntSummaryStatistics;
import java.util.stream.IntStream;

public class ConcatExample {

public static void main(String... args) {
IntStream a = IntStream.range(1, 5);
IntStream b = IntStream.range(100, 105);
IntStream c = IntStream.concat(a, b);
IntSummaryStatistics s = c.summaryStatistics();
System.out.println(s);
}
}

Output

IntSummaryStatistics{count=9, sum=520, min=1, average=57.777778, max=104}




See Also