My aim is to iterate through the values (Date objects) of the hashmap, convert them into Strings, then remove any that contain the three months. Please help.
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.HashMap;
import java.util.Locale;
import java.util.Calendar;
import java.util.Iterator;
import java.util.Map;
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")); //REMOVE
map.put("Lee", df.parse("OCTOBER 20 1994"));
map.put("Johnson", df.parse("OCTOBER 10 1994"));
map.put("May", df.parse("DECEMBER 31 1950"));
map.put("Cameron", df.parse("DECEMBER 20 1960"));
map.put("Brown", df.parse("DECEMBER 5 1960"));
map.put("Blair", df.parse("JULY 28 1950")); //REMOVE
map.put("Major", df.parse("FEBRUARY 10 1940"));
map.put("Thatcher", df.parse("MARCH 11 1960"));
map.put("Callaghan", df.parse("AUGUST 31 1920")); //REMOVE
return map;
}
public static void removeAllSummerPeople(HashMap<String, Date> map) {
Iterator <String> i = map.keySet().iterator();
while (i.hasNext()){
String value = (pair.getValue(it.next()));
if (value.contains("JUNE") | (value.contains("JULY") | (value.contains("AUGUST")))){
i.remove();
}
}
}
public static void main(String[] args) throws ParseException {
removeAllSummerPeople(createMap());
}
}