知乎专栏 |
前方插队
Stream<Integer> stream = Stream.of(1, 2, 3, 4); //Prepend 0 to the stream Stream<Integer> prependedStream = Stream.concat(Stream.of(0), stream); //Verify Stream prependedStream.forEach(System.out::print); //Prints 01234
末尾追加
Stream<Integer> stream = Stream.of(1, 2, 3, 4); //Append 5 and 6 to the stream Stream<Integer> appenededStream = Stream.concat(stream, Stream.of(5, 6)); //Verify Stream appenededStream.forEach(System.out::print); //Prints 123456