Suppose I have two streams of the same type. Is it possible to append one stream to the other without converting them to lists beforehand?
Example:
Stream<MyClass> ms = ...;
Stream<MyClass> ns = ...;
return ms.append(ns);
Yes.
Use Stream.concat(stream1, stream2)
, this will create a stream consisting of first the elements of stream1
and then the elements of stream2
, if you want to maintain ordering. Also note that all applied predicates, etc. still work on a per-stream basis, they do not automagically hold for the concatenation of the two streams.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With