集合嵌套之HashMap嵌套ArrayList

package com.czie.iot1913.lps.Map.MapTest00;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Set;

/**
* @author 1944900433@qq.com
* @date 2022-03-20 21:41
*/
public class ArrayListTest01 {
public static void main(String[] args) {
HashMap<String,ArrayList<String>> map = new HashMap<>();

ArrayList<String> list1 = new ArrayList<String>();
list1.add("诸葛亮");
list1.add("赵云");
map.put("三国演义",list1);
ArrayList<String> list2 = new ArrayList<String>();
list2.add("唐僧");
list2.add("孙悟空");
map.put("西游记",list2);
ArrayList<String> list3 = new ArrayList<String>();
list3.add("林冲");
list3.add("武松");
map.put("水浒传",list3);
Set<String> set = map.keySet();
for (String key:set){
ArrayList<String> value = map.get(key);
System.out.println(key+":");
for (String keymap:value){
System.out.println("\t"+keymap);
}
}

}
}

 

posted @ 2022-03-20 22:01  刘品水  阅读(67)  评论(0编辑  收藏  举报