List相同字段相加的JAVA实现

来源:互联网 发布:程序员交流 编辑:程序博客网 时间:2024/06/15 17:41
Map<Integer, Student> map = new HashMap<Integer, Student>();
        for (Student e : students) {
        int id = e.getStudentNo();
        if (map.containsKey(id)) {
        double score = map.get(id).getScore();
        score += e.getScore();
        map.get(id).setScore(score);
        } else {
        map.put(id, e);
        }
        System.out.println(map);
        }
        System.out.println(map);
0 0
原创粉丝点击