import java.util.*;
public class Demo {
public static void main(String[] args) {
HashMap<String, ArrayList<String>> hm = new HashMap<>();
ArrayList<String> city1 = new ArrayList<>();
ArrayList<String> city2 = new ArrayList<>();
ArrayList<String> city3 = new ArrayList<>();
Collections.addAll(city1,"南京市","扬州市","苏州市","无锡市","常州市");
Collections.addAll(city2,"武汉市","孝感市","十堰市","宜昌市","鄂州市");
Collections.addAll(city3,"石家庄市","唐山市","邢台市","保定市","张家口市");
hm.put("江苏省",city1);
hm.put("湖北省",city2);
hm.put("河北省",city3);
Set<Map.Entry<String, ArrayList<String>>> entries = hm.entrySet();
Set<String> set = hm.keySet();
for (String s : set) {
ArrayList<String> arrayList = hm.get(s);
StringJoiner sj = new StringJoiner(", ","","");
for (String s1 : arrayList) {
sj.add(s1);
}
System.out.println(s +" = "+ sj);
}
}
}
这是我自己写的一点代码,觉得有用可以点赞支持一下,谢谢啦!
有更好的建议发给我,我看到了都会回复的