Reputation: 4738
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);
Upvotes: 7
Views: 928
Reputation: 69349
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.
Upvotes: 14