public void iterateWithEntrySet(Map<String, Integer> map) {
for (Map.Entry<String, Integer> entry : map.entrySet()) {
System.out.println(entry.getKey() + ":" + entry.getValue());
}
}
public void iterateWithKeySetAndForeach(Map<String, Integer> map) {
for (String key : map.keySet()) {
System.out.println(key + ":" + map.get(key));
}
}
public void iterate(Map<String, Integer> map) {
for (Integer value : map.values()) {
System.out.println(value);
}
}
public void iterateWithIteratorAndEntry(Map<String, Integer> map) {
Iterator<Map.Entry<String, Integer>> iterator = map.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<String, Integer> entry = iterator.next();
System.out.println(entry.getKey() + ":" + entry.getValue());
}
}
public void iterateWithIteratorAndKeySet(Map<String, Integer> map) {
Iterator<String> iterator = map.keySet().iterator();
while (iterator.hasNext()) {
String key = iterator.next();
System.out.println(key + ":" + map.get(key));
}
}
public void iterateWithIteratorAndValues(Map<String, Integer> map) {
Iterator<Integer> iterator = map.values().iterator();
while (iterator.hasNext()) {
Integer value = iterator.next();
System.out.println("value :" + value);
}
}
public void iterateWithLambda(Map<String, Integer> map) {
map.forEach((k, v) -> System.out.println((k + ":" + v)));
}
public void iterateByKeysWithLambda(Map<String, Integer> map) {
map.keySet().foreach(k -> System.out.println((k + ":" + map.get(k))));
}
public void iterateValuesWithLambda(Map<String, Integer> map) {
map.values().forEach(v -> System.out.println(("value: " + v)));
}
public void iterateWithtreamAPI(Map<String, Integer> map) {
map.entrySet().stream()
// ... здесь какая-то другая потоковая обработка
.forEach(e -> System.out.println(e.getKey() + ":" + e.getValue()));
}