本帖最后由 心之信子 于 2014-8-18 18:42 编辑
import java.util.*;
class HashMapDemo
{
public static void main(String[] args)
{
HashMap<String,HashMap<String,String>> czbk = new HashMap<String,HashMap<String,String>>();
HashMap<String,String> yure = new HashMap<String,String>();
HashMap<String,String> jieye = new HashMap<String,String>();
czbk.put("jieyeban",jieye);
czbk.put("yureban",yure);
yure.put("01","zhangshan");
yure.put("02","lisi");
jieye.put("01","wangwu");
jieye.put("02","zhaoliu");
Iterator<String> it = czbk.keySet().iterator();
while(it.hasNext())
{
String roomName = it.next();
HashMap<String,String> room = czbk.get(roomName);
System.out.println(roomName);
Iterator<String> it1 = room.keySet().iterator();
while(it1.hasNext())
{
String id = it1.next();
String name = room.get(id);
System.out.println(id+":"+name);
}
}
}
}
输出结果为
jieyeban
01:wangwu
02:zhaoliu
yureban
01:zhangshan
02:lisi
请问一下,这个程序中只用到了Map集合中的HashMap为甚麽可以用迭代器?????
Iterator<String> it1 = room.keySet().iterator();
|
|