문제

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top