public static void removeAllSummerPeople(Map<String, Date> map) {
Iterator<Map.Entry<String, Date>> iterator = map.entrySet().iterator();
while (iterator.hasNext())
{
Map.Entry<String, Date> pair = iterator.next();
String key = pair.getKey();
Date date = pair.getValue();
if (date.getMonth() > 5 && date.getMonth() < 9){
iterator.remove();
}
}
}
package com.javarush.task.task08.task0816;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.Date;
/*
Добрая Зинаида и летние каникулы
*/
@SuppressWarnings("ALL")
public class Solution {
public static Map<String, Date> createMap() throws ParseException {
DateFormat dateFormat = new SimpleDateFormat("MMMMM d yyyy", Locale.ENGLISH);
Map<String, Date> map = new HashMap<>();
map.put("Смирнов", dateFormat.parse("MAY 1 2012"));
map.put("Ffge", dateFormat.parse("MAY 1 2012"));
map.put("Gergerg", dateFormat.parse("MAY 1 2012"));
map.put("Eerg", dateFormat.parse("June 1 2012"));
map.put("Verggg", dateFormat.parse("MAY 1 2012"));
map.put("Vergerg", dateFormat.parse("MAY 1 2012"));
map.put("Begfdvd", dateFormat.parse("MAY 1 2012"));
map.put("Vdfbdfb", dateFormat.parse("MAY 1 2012"));
map.put("Ddfbbfrd", dateFormat.parse("MAY 1 2012"));
map.put("Vdfdrg", dateFormat.parse("MAY 1 2012"));
return map;
}
public static void removeAllSummerPeople(Map<String, Date> map) {
Iterator<Map.Entry<String, Date>> iterator = map.entrySet().iterator();
while (iterator.hasNext())
{
Map.Entry<String, Date> pair = iterator.next();
String key = pair.getKey();
Date date = pair.getValue();
if (date.getMonth() > 5 && date.getMonth() < 9){
iterator.remove();
}
}
}
public static void main(String[] args) {
// System.out.println(removeAllSummerPeople(createMap()));
//
}
}