练习 map集合被使用是因为具备映射关系 "进度班" "01" "张三" "进度班" "02" "李四" "J1701" "01" "王五" "J1701" "02" "王二" 此信息中,我们要怎样把上述信息装入集合中, 根据班级信息的到所有的所有信

package com.rf.xs;

import java.util.Arrays;

public class Student01 {
String name;
int age;
public Student01(String name,int age) {
this.name=name;
this.age=age;

}
@Override
public String toString() {
return "Student01 [name=" + name + ", age=" + age + "]";
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}

}

package com.rf.xs;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

public class XuanBanJi {
public static void main(String[] args) {
ArrayList<Student01> i = new ArrayList<Student01>();
i.add(new Student01("张三",18));
i.add(new Student01("李四",19));
i.add(new Student01("王五",15));
ArrayList<Student01> j = new ArrayList<Student01>();
j.add(new Student01("小强",21));
j.add(new Student01("小明",19));
j.add(new Student01("小红",17));
HashMap<String, ArrayList<Student01>> classes = new HashMap<String, ArrayList<Student01>>();
classes.put("J1702", i);
classes.put("J1704", j);
Set<Map.Entry<String, ArrayList<Student01>>> entry = classes.entrySet();
Iterator<Map.Entry<String, ArrayList<Student01>>> iterator = entry.iterator();
while(iterator.hasNext()){
Entry<String, ArrayList<Student01>> stu = iterator.next();
String it = stu.getKey();
System.out.println(it);
ArrayList<Student01> s = stu.getValue();
for(Student01 t:s){
System.out.println("\t"+t.getName()+" "+t.getAge());
}
}
}

}

上一篇:Timer Design in StatusBar


下一篇:StarUML 系列,静态图与动态图,用例图,类图【ps:熟悉一下starUML】