如下创建一个HashMap,
HashMap<String, ArrayList<Integer>> studentMap=new HashMap<String, ArrayList<Integer>>();
键是学生的姓名,值是他们的分数列表。ArrayList中的索引0对每个学生都有1月的标记,索引1对每个学生具有feb的标记,然后继续(如果有更多的话)。
您可以添加以下条目,
scores=new ArrayList<Integer>(); scores.add(40); scores.add(80); studentMap.put("John", scores); scores=new ArrayList<Integer>(); scores.add(61); scores.add(81); studentMap.put("Mary", scores);为了显示这些值,
for(String name : studentMap.keySet()) { ArrayList<Integer> scoreList=studentMap.get(name); System.out.println("Name : "+name+" Jan Score: "+scoreList.get(0)+" Feb Score : "+scoreList.get(1)); }在这两者之间,您可以添加逻辑以提高百分比。



