package com.cy.test21;import java.util.ArrayList;import java.util.HashMap;import java.util.Set;/*** map结合嵌套list集合*/public class MapIncludList {public static void main(String[] args) {HashMap<String, ArrayList<String>> map = new HashMap<String, ArrayList<String>>();ArrayList<String> list1 = new ArrayList<>();list1.add("诸葛亮");list1.add("赵云");map.put("三国演义", list1);ArrayList<String> list2 = new ArrayList<>();list2.add("唐僧");list2.add("孙悟空");map.put("西游记", list2);ArrayList<String> list3 = new ArrayList<>();list3.add("鲁智深");list3.add("武松");map.put("水浒传", list3);//获得map集合的键值Set<String> keys = map.keySet();for (String key : keys) {System.out.println(key);//通过键值来遍历valueArrayList<String> list = map.get(key);for (String value : list) {System.out.println("\t" + value);}}}}
600字范文,内容丰富有趣,生活中的好帮手!