1、使用entrySet()和stream()方法结合遍历Map
Map<String, String> map = new HashMap<>();map.put("A001", "zhangsan");map.put("A002", "lisi");map.entrySet().stream().forEach(entry -> {String key = entry.getKey();String value = entry.getValue();System.out.println(key + " = " + value);});
结果:
A001 = zhangsan
A002 = lisi