Drucken Sie Karte Java
map.forEach((key, value) -> System.out.println(key + ":" + value));
goncalo2727
map.forEach((key, value) -> System.out.println(key + ":" + value));
Map<String, Integer> map = new HashMap<>();
map.put("a", 1);
map.put("b", 2);
System.out.println(Arrays.asList(map)); // method 1
System.out.println(Collections.singletonList(map)); // method 2
for (Map.Entry<String, Object> entry : map.entrySet()) {
System.out.println(entry.getKey() + ":" + entry.getValue().toString());
}
// Java 8 - Collection.iterator() + Iterator.forEachRemaining()
map.keySet().iterator()
.forEachRemaining(System.out::println);