s-day04--集合的嵌套
This commit is contained in:
@@ -0,0 +1,26 @@
|
|||||||
|
package com.inmind.map01;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
/*
|
||||||
|
8.集合的嵌套
|
||||||
|
使用集合的嵌套,显示哪个省份有哪些城市
|
||||||
|
省份作为Key String
|
||||||
|
城市作为值(有很多数据,容器集合)
|
||||||
|
*/
|
||||||
|
public class Demo07 {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Map<String, ArrayList<String>> map = new HashMap<>();
|
||||||
|
ArrayList<String> jsList = new ArrayList<>();
|
||||||
|
Collections.addAll(jsList, "南京", "无锡", "徐州", "常州","苏州" );
|
||||||
|
ArrayList<String> zjList = new ArrayList<>();
|
||||||
|
Collections.addAll(zjList, "杭州", "宁波", "温州", "嘉兴","湖州" );
|
||||||
|
map.put("江苏省", jsList);
|
||||||
|
map.put("浙江省", zjList);
|
||||||
|
Set<Map.Entry<String, ArrayList<String>>> entries = map.entrySet();
|
||||||
|
for (Map.Entry<String, ArrayList<String>> entry : entries) {
|
||||||
|
System.out.println(entry.getKey()+":"+entry.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user