List相同字段相加的JAVA实现

Map map = new HashMap();
        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);

你可能感兴趣的:(JAVA技术)