首页 > 其他 > 详细

list转map(JDK8-Lambda表达式)

时间:2019-12-27 09:13:09      阅读:197      评论:0      收藏:0      [点我收藏+]
public static void main(String[] args) {
    Student student1 = new Student();
    student1.setId(110);
    student1.setName("李明");
    student1.setAge(23);

    Student student2 = new Student();
    student2.setName("明浩");
    student2.setId(119);
    student2.setAge(24);

    List<Student> list = Lists.newArrayList();
    list.add(student1);
    list.add(student2);

    Map<Integer, Student> studentMap = list.stream().collect(Collectors.toMap(Student:: getId, (k) -> k));

    System.out.println(JSON.toJSONString(studentMap));
}

list转map(JDK8-Lambda表达式)

原文:https://www.cnblogs.com/JimmyThomas/p/12105272.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!