Advertisement
FedchenkoIhor

HashMap_Date_iterator_hasNext

May 25th, 2016
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.62 KB | None | 0 0
  1. package com.javarush.test.level.lesson.task;
  2.  
  3. import java.util.Date;
  4. import java.util.HashMap;
  5. import java.util.Iterator;
  6. import java.util.Map;
  7.  
  8. /* Удалить всех людей, родившихся летом
  9. Создать словарь (Map<String, Date>) и занести в него десять записей по принципу: «фамилия» - «дата рождения».
  10. Удалить из словаря всех людей, родившихся летом.
  11. */
  12.  
  13. public class Solution {
  14.     public static HashMap<String, Date> createMap() {
  15.         HashMap<String, Date> map = new HashMap<String, Date>();
  16.         map.put("Stallone", new Date("JUNE 1 1980"));
  17.         map.put("Qtallone", new Date("JANUARY 1 1980"));
  18.         map.put("Wtallone", new Date("FEBRUARY 1 1980"));
  19.         map.put("Etallone", new Date("MARCH 1 1980"));
  20.         map.put("Rtallone", new Date("APRIL 1 1980"));
  21.         map.put("Ytallone", new Date("MAY 1 1980"));
  22.         map.put("Utallone", new Date("JUNE 1 1980"));
  23.         map.put("Itallone", new Date("JULY 1 1980"));
  24.         map.put("Otallone", new Date("AUGUST 1 1980"));
  25.         map.put("Ptallone", new Date("SEPTEMBER 1 1980"));
  26.  
  27.         return map;
  28.     }
  29.  
  30.     public static void removeAllSummerPeople(HashMap<String, Date> map) {
  31.         Iterator<Map.Entry<String, Date>> iterator = map.entrySet().iterator();
  32.         while (iterator.hasNext()) {
  33.             Map.Entry<String, Date> pair = iterator.next();
  34.             if (pair.getValue().getMonth() > 4 && pair.getValue().getMonth() < 8) {
  35.                 iterator.remove();
  36.             }
  37.         }
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement