Java lambda子列表 [英] Java lambda sublist

查看:123
本文介绍了Java lambda子列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过Java 8 lambda表达从列表A获取新列表B条件的最短途径是什么?

What is the shortest way to express "get new List B from List A where condition" via a Java 8 lambda?

说我有 List< Integer> a = Arrays.asList(1,2,3,4,5),我想要一个新的List,B,值> 3。

Say I have List<Integer> a = Arrays.asList(1, 2, 3, 4, 5) and I want a new List, B, where the value is > 3.

我已经阅读了新的Collections Streams API,但我不相信我已经找到了最好的方法来做到这一点,不想污染这个问题,可能是我不太完美的解决方案。

I've read through the new Collections Streams API, but I'm not convinced I have found the best way to do this, and don't want to taint the question with what is probably my less than perfect solution.

推荐答案

a.stream().filter(x -> x > 3).collect(Collectors.toList());

这篇关于Java lambda子列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆