HashMap嵌套ArrayList的代码实现
HashMap
HashMap
ArrayList
array1.add("吕布");
array1.add("周瑜");
hm.put("三国演义", array1);
ArrayList
array2.add("令狐冲");
array2.add("林平之");
hm.put("笑傲江湖", array2);
ArrayList
array3.add("郭靖");
array3.add("杨过");
hm.put("神雕侠侣", array3);
Set
for (String key :set) {
System.out.println(key);
ArrayList
for (String s : value) {
System.out.println("\t"+s);
}
}
结果:
三国演义
吕布
周瑜
笑傲江湖
令狐冲
林平之
神雕侠侣
郭靖
杨过
ArrayList嵌套HashMap
ArrayList
ArrayList
HashMap
HashMap
HashMap
map1.put("周瑜", "小乔");
map1.put("吕布", "貂蝉");
map2.put("郭靖", "黄蓉");
map2.put("杨过", "小龙女");
map3.put("令狐冲", "任盈盈");
map3.put("林平之", "岳灵珊");
list.add(map1);
list.add(map2);
list.add(map3);
for(int i=0;i
Set
for (String str : set) {
String value = map.get(str);
System.out.println(str+"-------"+value);
}
}
吕布-------貂蝉
周瑜-------小乔
杨过-------小龙女
郭靖-------黄蓉
令狐冲-------任盈盈
林平之-------岳灵珊