黑马程序员技术交流社区
标题:
HashMap多重映射的程序
[打印本页]
作者:
ò壞尛孩
时间:
2014-4-23 22:49
标题:
HashMap多重映射的程序
本帖最后由 ò壞尛孩 于 2014-4-23 23:44 编辑
import java.util.*;
class MapDemo3
{
public static void main(String[] args)
{
HashMap <String,HashMap<String,String>> heima=new HashMap<String,HashMap<String,String>>();
HashMap<String,String> classAndroid=new HashMap<String,String>();
HashMap<String,String> classCloudComputing=new HashMap<String,String>();
heima.put("安卓班",classAndroid);
heima.put("云计算班",classCloudComputing);
classAndroid.put("001","zhangsan");
classAndroid.put("002","lisi");
classCloudComputing.put("001","wangwu");
classCloudComputing.put("002","zhaoliu");
getStudentInfo(classAndroid);
getStudentInfo(classCloudComputing);
getStudentInfo1(heima);
}
public static void getStudentInfo(HashMap<String,String> roomMap)
{
Iterator<String> it =roomMap.keySet().iterator();
while(it.hasNext())
{
String id=it.next();
String name=roomMap.get(id);
System.out.println(id+":"+name);
}
}
public static void getStudentInfo1(HashMap <String,HashMap<String,String>> roomMap)
{
Iterator<String> it=roomMap.keySet().iterator();
while(it.hasNext())
{
String roomname=it.next();
HashMap<String,String> room=roomMap.get(roomname);
System.out.println(roomname);
getStudentInfo(room);
}
}
}
复制代码
QQ截图20140423234405.png
(47 KB, 下载次数: 2)
下载附件
2014-4-23 23:44 上传
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2