Java 8 Streams Java Java API
Interface:
java.util.stream.Stream
Method:
static <T> Stream<T> concat(Stream<? extends T> a,
Stream<? extends T> 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.stream;
import java.util.Arrays; import java.util.stream.Stream;
public class ConcatExample {
public static void main(String... args) { Stream<String> s1 = Arrays.asList("one", "two", "three").stream(); Stream<String> s2 = Arrays.asList("four", "five", "six").stream();
Stream<String> s3 = Stream.concat(s1, s2); s3.forEach(System.out::println); } }
Outputone two three four five six
|
|