다음 레벨 이후에 기억에 남는 몇 가지 주제를 새로 고치기 위해 몇 가지 작업을 맡겼습니다. 반복자에 문제가 발생했습니다. 여기에 걸어두고 작업 방법을 상기시켜 줍니다(갑자기 필요한 경우). 그리고 다음과 같이 맵에서 객체를 삭제할 수도 있습니다(반복자가 깨지지 않도록 맵을 복사하고 원본 맵의 모든 것을 삭제합니다) ):
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