集合框架:对两个集合对象的操作



有两个集合:-

c1=包括所有女性员工

c2=年龄大于40岁(年龄>40(的所有员工。

如何找到年龄超过40岁的所有女性员工?

c1.stream().filter(c2::contains).collect(Collectors.toList());//Last step is optional. Only use it, if you want a list of it.

stream():从第一个集合创建一个流。(Java 8+(

然后filter()也被c2中的那些。

然后有选择地从中列出一个列表。

最新更新