Python 官方文档:入门教程 => 点击学习
目录使用stream从List对象中获取某列数据stream通过List里对象中某个属性最小来取该最小对象总结使用stream从List对象中获取某列数据 在 jdk 8 中增加了
在 jdk 8 中增加了 stream 的特性,使用非常的方便。
这里,介绍通过 stream 从 List 中获取某列数据。
List<Student> list = new ArrayList<>();
list.add(new Student(1L, "张三", 1));
list.add(new Student(2L, "李四", 2));
list.add(new Student(3L, "王五", 3));
System.out.println(list);
List<String> collect = list.stream().map(Student::getName).collect(Collectors.toList());
System.out.println(collect);
输出结果如下:
[Student(id=1, name=张三, gender=1), Student(id=2, name=李四, gender=2), Student(id=3, name=王五, gender=3)]
[张三, 李四, 王五]
代码实现(Entity为实体)
List.stream().min(Comparator.comparing(Entity::getAge)).get();
以上为个人经验,希望能给大家一个参考,也希望大家多多支持编程网。
--结束END--
本文标题: 如何使用stream从List对象中获取某列数据
本文链接: https://www.lsjlt.com/news/175683.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0