Stream concat(Stream a, Stream b) example
Description
Stream concat(Stream<? extends T> a,
Stream<? extends T> b)
creates a concatenated stream.
Syntax
concat
has the following syntax.
static <T> Stream<T> concat(Stream<? extends T> a, Stream<? extends T> b)
Example
The following example shows how to use concat
.
import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;
/*from w ww .j a v a2 s .c o m*/
public class Main {
public static void main(String[] args) {
List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5);
List<Integer> numbers1 = Arrays.asList(1, 2, 3, 4, 5);
Stream<Integer> s = Stream.concat(numbers.stream(),
numbers1.stream());
System.out.println(s.count());
}
}
The code above generates the following result.