Home | 简体中文 | 繁体中文 | 杂文 | Github | 知乎专栏 | Facebook | Linkedin | Youtube | 打赏(Donations) | About
知乎专栏

11.13. 合并 Stream

前方插队

		
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