Пробовал через итератор, все получилось, а таким способом не получается. Объясните что я не так понял, пожалуйста
package com.javarush.task.task08.task0818;
import java.util.HashMap;
import java.util.Map;
/*
Только для богачей
*/
public class Solution {
public static Map<String, Integer> createMap() {
Map<String, Integer> map = new HashMap<>();
map.put("qwe", 123);
map.put("qwe1", 1231);
map.put("qwe2", 123);
map.put("qwe3", 523);
map.put("qwe4", 423);
map.put("qwe5", 533);
map.put("qwe6", 4123);
map.put("qwe7", 13);
map.put("qwe8", 163);
map.put("qwe9", 623);
return map;
}
public static void removeItemFromMap(Map<String, Integer> map) {
for (Map.Entry<String, Integer> pair : map.entrySet())
{
int value = pair.getValue();
String key = pair.getKey();
if (value > 500) map.remove(key);
}
}
public static void main(String[] args) {
}
}