java练习-集合遍历
package com.example.ss_0203_array.test.test_0815; import java.util.*; public class test1 { public static void main(String[] args) { HashMap<String, ArrayList> hMap = new HashMap<>(); ArrayList city1 = new ArrayList<>(); city1.add("AAA1"); city1.add("AAA2"); city1.add("AAA3"); city1.add("AAA4"); ArrayList city2 = new ArrayList<>(); city2.add("BBB1"); city2.add("BBB2"); city2.add("BBB3"); city2.add("BBB4"); ArrayList city3 = new ArrayList<>(); city3.add("CCC1"); city3.add("CCC2"); city3.add("CCC3"); city3.add("CCC4"); hMap.put("A",city1); hMap.put("B",city2); hMap.put("C",city3); Set<Map.Entry<String, ArrayList>> entries = hMap.entrySet(); for (Map.Entry<String, ArrayList> entry : entries) { String key = entry.getKey(); ArrayList<String> value = entry.getValue(); StringJoiner sj = new StringJoiner(",","",""); for (String city : value) { sj.add(city); } System.out.println(key + "==" + sj); } } }