HashMap嵌套ArrayList使用
// 需求:
// 假设HashMap集合的元素是ArrayList.有3个。
// 每一个ArrayList集合的值是字符串。
// 元素我已经完成,请遍历。
// 结果:
// 三国演义
// 吕布
// 周瑜
// 笑傲江湖
// 令狐冲
// 林平之
// 神雕侠侣
// 郭靖
// 杨过
package cn.zsp.map_study_06;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Set;
// 需求:
// 假设HashMap集合的元素是ArrayList.有3个。
// 每一个ArrayList集合的值是字符串。
// 元素我已经完成,请遍历。
// 结果:
// 三国演义
// 吕布
// 周瑜
// 笑傲江湖
// 令狐冲
// 林平之
// 神雕侠侣
// 郭靖
// 杨过
public class HashMap_ArrayList {
public static void main(String[] args) {
HashMap<String, ArrayList<String>> book=new HashMap<String,ArrayList<String>>();
ArrayList<String> sanguo= new ArrayList<String>();
ArrayList<String> jianghu=new ArrayList<String>();
ArrayList<String> shendiao=new ArrayList<String>();
sanguo.add("吕布");
sanguo.add("周瑜");
jianghu.add("令狐冲");
jianghu.add("林平之");
shendiao.add("郭靖");
shendiao.add("杨过");
book.put("第1本",sanguo);
book.put("第2本",jianghu);
book.put("第3本",shendiao);
Set<String> bookset= book.keySet();
for (String bookkey:bookset)
{
System.out.println(bookkey);
for (String x : book.get(bookkey))
{
System.out.println(x);
}
}
}
}