June 2018
Beginner
722 pages
18h 47m
English
The Stream<T> concatenate (Stream<> a, Stream<T> b) static method of the Stream interface creates a stream of values based on two Stream objects, a and b, passed in as the parameters. The newly created stream consists of all the elements of the first parameter, a, followed by all of the elements of the second parameter, b. The following code demonstrates this method of Stream object creation:
Stream<Integer> stream1 = List.of(1, 2).stream();Stream<Integer> stream2 = List.of(2, 3).stream();Stream.concat(stream1, stream2) .forEach(System.out::print); //prints: 1223
Notice that the 2 element is present in both original streams, and consequently, it is present twice in the resulting stream.
Read now
Unlock full access