public String toString() {
return id + "<---->" + name;
}
}
public class MapDemo {
public static void main(String[] args) {
TreeMap<String, List<Save>> czbk = new TreeMap<String, List<Save>>();// 嵌套容器
List<Save> Javayureban = new ArrayList<Save>();// list容器
List<Save> Uiyureban = new ArrayList<Save>();
czbk.put("JAVA", Javayureban);
czbk.put("UI", Uiyureban);
Javayureban.add(new Save("01", "LaoWang"));
Javayureban.add(new Save("02", "XiaoWang"));
Uiyureban.add(new Save("01", "LaoLi"));
Uiyureban.add(new Save("02", "XiaoLi"));
/*
* Iterator<Map.Entry<String,
* List<Save>>>it=czbk.entrySet().iterator();//entrySet取出方法
* while(it.hasNext()){ Map.Entry<String, List<Save>>
* hmc=it.next();//取出键值对 String kc=hmc.getKey(); List<Save> bj
* =hmc.getValue(); //分别获取键和值 System.out.println(kc+bj); }
*/
Iterator<String> it = czbk.keySet().iterator();// KeySet取出方法
while (it.hasNext()) {
String kc = it.next();
List<Save> bj = czbk.get(kc);// 用czbk容器的get(KEY)方法取出与Key存在映射关系的Value.
/*本来这里想提问来的后来看到了编译软件注解知道了原来取出的正是和key想匹配的value值
get
public V get(Object key)Returns the value to which the specified key is mapped,
or null if this map contains no mapping for the key.
中文意思:public V get(Object key)返回指定键映射到的值,如果此映射不包含密钥映射,则为null。
*/
System.out.println(kc);
getInfo(bj);
}
}