```
package com.company;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author2020-10-09-08:03
*/
public class SetDemo {
public static void main(String[] args) {
List<Student> list= new ArrayList<>();
list.add(new Student("一三",10,80,"class03"));
list.add(new Student("一三",18,90,"class04"));
//每个班的成绩列表
Map<String, List<Integer>> mapColass2Scores= new HashMap<>();
for(Student s:list)
{
if(mapColass2Scores.containsKey(s.getClassNum()))
{
//拿到当前班级的学生成绩列表对像
List<Integer> lst= mapColass2Scores.get(s.getClassNum());
lst.add(s.getScore());
}
else //该学生所在班级,第一次加入到map中
{
List<Integer> lst= new ArrayList<>();
lst.add(s.getScore());
mapColass2Scores.put(s.getClassNum(),lst);
}
}
for(Map.Entry entry: mapColass2Scores.entrySet())
{
// System.out.println("班级:" + entry.getKey());
List<Integer> listScores= (List<Integer>) entry.getValue();
// System.out.println("班级分数:" + listScores);
int sum= 0;
for(Integer score: listScores)
{
sum+= score;
}
System.out.println("班级:" + entry.getKey() +"平均分:" + sum);
}
System.out.println("");
int age_sum= 0;
for(Student s:list)
{
age_sum+= s.getAge();
}
System.out.println("平均年龄:" + age_sum/list.size());
}
}
```