I left myself a few tasks to refresh some topics in my memory after the next levels. There was a problem with the iterator. Let it hang here and remind you how to work with it (if you suddenly need it): And you can also delete objects from the map like this (copy the map so that the iterator does not break, and delete everything in the original map):
public static void removeAllSummerPeople(HashMap
map) { //write your code here Iterator
> iterator=map.entrySet().iterator(); while (iterator.hasNext()){ Map.Entry
pair=iterator.next(); int month=pair.getValue().getMonth(); if(month>=5&&month<8){ iterator.remove(); } } }
Map
map = new HashMap<>(); map.put("1", "2"); map.put("3", "4"); Map
mapCopy = new HashMap<>(map); for(Map.Entry
pair : mapCopy.entrySet()) { map.remove(pair.getKey()); }
GO TO FULL VERSION