-
-
Save kacper-kuczek/e7852ef6a6ee4442fec9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.stream.Stream; | |
| import org.junit.Test; | |
| import static java.util.function.Function.identity; | |
| public class StreamConcat { | |
| @SafeVarargs | |
| public static <T> Stream<T> concatenate(Stream<? extends T>... streams) { | |
| return Stream.of(streams).reduce(Stream.empty(), Stream::concat).map(identity()); | |
| } | |
| @Test | |
| public void learnAboutConcatenate() { | |
| Stream<CharSequence> res = concatenate( | |
| Stream.of("One"), | |
| Stream.of(new StringBuffer("Two")), | |
| Stream.of(new StringBuilder("Three")) | |
| ); | |
| res.forEach(System.out::println); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment