我如何追加两股气流在Java中8? [英] How do I append two Streams in Java 8?
本文介绍了我如何追加两股气流在Java中8?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有两个相同类型的流。是否有可能追加一个流的另一种没有将它们转换为事先列出?
例如:
流< MyClass的>毫秒= ...;
流< MyClass的>纳秒= ...;
返回ms.append(纳秒);
解决方案
是
使用 Stream.concat(STREAM1,STREAM2)
,这将创建一个包含第一个流1
然后流2
的如果的你想保持顺序。另外请注意,所有应用的predicates等在每个流的基础上仍然可以工作,他们并不自动地保持两个流的串联。
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.
这篇关于我如何追加两股气流在Java中8?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文