import java.util.ArrayList;
import java.util.HashMap;
import java.util.*;
public class RunoobTest {
public static void main(String[] args) {
/*
// 创建 HashMap 对象 Sites
HashMap<Integer, String> Sites = new HashMap<Integer, String>();
// 添加键值对
Sites.put(1, "Google");
Sites.put(2, "Runoob");
Sites.put(3, "Taobao");
Sites.put(4, "Zhihu");
// 输出 key 和 value
for (Integer i : Sites.keySet()) {
System.out.println("key: " + i + " value: " + Sites.get(i));
}
// 返回所有 value 值
for (String value : Sites.values()) {
// 输出每一个value
System.out.print(value + ", ");
}
System.out.println("\n");
System.out.println("==========================================");
ArrayList<String> sites2 = new ArrayList<String>();
sites2.add("Google");
sites2.add("Runoob");
sites2.add("Taobao");
sites2.add("Weibo");
for (String i : sites2) {
System.out.println(i);
}
System.out.println("\n");
System.out.println("==========================================");
*/
// /*
// * List中的Map
// * */
/*
List<Map<String, Object>> mapList = new ArrayList<>();
Map<String, Object> map = new HashMap<>();
map.put("11", "22");
map.put("33", "44");
map.put("55", "66");
mapList.add(map);
// Map<String, Object> map2 = new HashMap<>();
// map2.put("77", "88");
// mapList.add(map2);
System.out.println("[数组] 这是输出整个List:" + mapList);
mapList.forEach((str) -> {
System.out.println("{集合} 这是输出List中的Map" + str);
System.out.println("[数组] 这是循环遍历Map中的数据:" + "key:" + str.keySet() + "values: " + str.values());
System.out.print("(字符串) 这是遍历的key: ");
str.keySet().forEach(string -> {
System.out.print(string + ",");
});
System.out.println();
System.out.print("(字符串) 这是遍历的values: ");
str.values().forEach(strings -> {
System.out.print(strings + ",");
});
System.out.println();
});
*/
System.out.println("#########################################################################");
// /*
// * Map中的List
// * */
Map<String, List<String>> listMap = new HashMap<>();
List<String> list = new ArrayList<>();
list.add("AA");
list.add("BB");
list.add("CC");
listMap.put("1", list);
List<String> list11 = new ArrayList<>();
list11.add("aa");
list11.add("bb");
list11.add("cc");
listMap.put("11", list11);
System.out.println("{集合} 这是Map" + listMap);
System.out.println("[数组] 这是Map中的键值 key:" + listMap.keySet() + "value: " + listMap.values() + " Entry:" + listMap.entrySet());
listMap.values().forEach(strings -> {
System.out.println("[数组] 这是Map中的values: " + strings);
System.out.print("(字符串) 这是values值 List<String>: ");
strings.forEach(str -> {
System.out.print(str + ",");
});
System.out.println();
});
System.out.println("#########################################################################");
Map<List<String>, List<String>> listListMap = new HashMap<>();
List<String> list2 = new ArrayList<>();
list2.add("QQ");
list2.add("EE");
list2.add("WW");
List<String> list3 = new ArrayList<>();
list3.add("q");
list3.add("e");
list3.add("w");
listListMap.put(list2, list3);
System.out.println("listListMap: " + listListMap);
System.out.println("listListMap.keySet(): " + listListMap.keySet());
System.out.println("listListMap.entrySet(): " + listListMap.entrySet());
System.out.println("listListMap.values(): " + listListMap.values());
listListMap.values().forEach(str -> {
System.out.println("listListMap.values().forEach(str: " + str);
str.forEach(string -> {
System.out.println("str.forEach(string " + string);
});
});
System.out.println();
System.out.println("#########################################################################");
Map<List<String>, Map<String, Object>> mapMap = new HashMap<>();
List<String> list5 = new ArrayList<>();
list5.add("QQ");
list5.add("EE");
list5.add("WW");
Map<String, Object> map1 = new HashMap<>();
map1.put("11", "22");
map1.put("11", "22");
map1.put("11", "22");
mapMap.put(list5, map1);
System.out.println("mapMap -- " + mapMap);
for (Map.Entry<List<String>, Map<String, Object>> map2 : mapMap.entrySet()) {
System.out.println("map2.getKey() -- " + map2.getKey());
System.out.println("map2.getValue() -- " + map2.getValue());
}
mapMap.keySet().forEach(strings -> {
System.out.println(strings);
strings.forEach(str -> {
System.out.print(str);
});
});
System.out.println("\n");
System.out.println(mapMap.entrySet());
System.out.println("mapMap.values() -- " + mapMap.values());
mapMap.values().forEach(str -> {
System.out.println("str -- " + str);
System.out.println("str.keySet() -- " + str.keySet());
System.out.println("str.values() -- " + str.values());
str.values().forEach(string -> {
System.out.println("string -- " + string);
});
});
}
}