【发布时间】:2019-05-29 23:33:21
【问题描述】:
我有一个对象列表 N,其中 N 是
N
|--- type (1,2,3)
|--- A (applicable if type 1)
|--- B (applicable if type 2)
|--- C (applicable if type 3)
|--- List<Integer> p
现在,我想要的结果是 List 的过滤版本,这样:
create a list List<Integer> l
先这样做:
if(type == 1) && (A > some_value):
Add all elements of p to l
select this N
L 形成后:
if(type != 1)
if(l contains any element from p):
select this N
如何一步一步使用流来实现这一点?
我可以先过滤并创建一个列表“l”,然后使用该列表进行过滤。
l = stream.filter(a -> a.type == 1 && a.A > some_value).collect(..)
然后,使用 l 进一步过滤。
但是有没有更好更精确的方法呢?
【问题讨论】:
-
您的数据结构可能不适合您需要执行的操作。这是来自第三方的数据结构还是您自己的数据结构。如果你能解释你的意图可能是最好的。
标签: java collections java-8 java-stream