die Monate werden richtig identifiziert - 6, 7 & 8 entsprechen den Sommermonaten und die entsprechenden Personen sollen entfernt werden. Aber anscheinend tut it.remove();
nicht das Gewünschte. Was ist hier falsch?
package de.codegym.task.task08.task0816;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
/*
Die liebe Emma und die Sommerferien
*/
public class Solution {
public static HashMap<String, Date> mapErstellen() throws ParseException {
DateFormat df = new SimpleDateFormat("MMMMM d yyyy", Locale.ENGLISH);
HashMap<String, Date> map = new HashMap<String, Date>(10);
map.put("Stallone", df.parse("JUNE 15 1980"));
map.put("Seagal", df.parse("APRIL 19 1981"));
map.put("Willis", df.parse("JULY 21 1980"));
map.put("Schwarzenegger", df.parse("MARCH 12 1981"));
map.put("Douglas", df.parse("SEPTEMBER 11 1980"));
map.put("Robbie", df.parse("OCTOBER 31 1981"));
map.put("Theron", df.parse("DECEMBER 21 1980"));
map.put("Kidman", df.parse("FEBRUARY 14 1981"));
map.put("Cruise", df.parse("MAY 13 1980"));
map.put("Eastwood", df.parse("NOVEMBER 21 1981"));
return map;
//schreib hier deinen Code
}
public static void alleSommergeburtstagskinderEntfernen(HashMap<String, Date> map) {
//schreib hier deinen Code
// HashMap<String, Date> help = map;
int month = 0;
// Set entrySet = help.entrySet();
Set entrySet = map.entrySet();
Iterator it = entrySet.iterator();
while (it.hasNext()) {
//for(Map.Entry<String,Date> entry : help.entrySet()){
//remove every entry wich was born in the summer
Map.Entry entry = (Map.Entry) it.next();
Date tmp = (Date) entry.getValue();
month = tmp.getMonth();
// System.out.println("Monat: " + month);
if ((month > 5) && (month < 9)) {
//help.remove(entry.getKey());
// System.out.println("Monat " + month + " wird entfernt");
it.remove();
}
// map = help;
}
}
public static void main (String[]args) throws ParseException {
HashMap<String, Date> map = mapErstellen();
alleSommergeburtstagskinderEntfernen(map);
}
}