Created an iterator, but still getting a concurrent modification error. What am I missing?
package com.codegym.task.task08.task0816;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.*;
import java.util.Locale;
/*
Kind Emma and the summer holidays
*/
public class Solution {
public static HashMap<String, Date> createMap() throws ParseException {
DateFormat df = new SimpleDateFormat("MMMMM d yyyy", Locale.ENGLISH);
HashMap<String, Date> map = new HashMap<String, Date>();
map.put("Stallone", df.parse("JUNE 1 1980"));
//write your code here
map.put("a", df.parse("JULY 1 1980"));
map.put("b", df.parse("AUGUST 1 1980"));
map.put("c", df.parse("SEPTEMBER 1 1980"));
map.put("d", df.parse("OCTOBER 1 1980"));
map.put("e", df.parse("NOVEMBER 1 1980"));
map.put("f", df.parse("DECEMBER 1 1980"));
map.put("g", df.parse("JANUARY 1 1980"));
map.put("h", df.parse("FEBRUARY 1 1980"));
map.put("i", df.parse("MARCH 1 1980"));
return map;
}
public static void removeAllSummerPeople(HashMap<String, Date> map) {
//write your code here
Iterator<Map.Entry<String, Date>> iterator = map.entrySet().iterator();
while (iterator.hasNext()){
Map.Entry<String, Date> pair = iterator.next();
int month = pair.getValue().getMonth();
if(month > 4 && month < 8){
map.remove(pair.getKey());
}
}
}
public static void main(String[] args) throws ParseException {
}
}