Why validator doesn't like this code? It works fine.

public static void removeAllSummerPeople(HashMap<String, Date> map)
{
    IteratorXXX iterator = map.entrySet().iterator();

    while (iterator.hasNext()) {
    Map.Entry<String, Date> entry = iterator.next();
    Date summerBegin = new Date()
    Date summerEnd = new GregorianCalendar(2016, 8, 22);
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(entry.getValue());
    calendar.set(Calendar.YEAR, 2016);
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
    String formatted = format.format(summerBegin.getTime());
    System.out.println(formatted + ": " + calendar.compareTo(summerBegin));
    if (calendar.compareTo(summerBegin) >= 0 && calendar.compareTo(summerEnd) < 0)
        iterator.remove();
    }
}

Instead of

IteratorXXX

there is Iterator < Map < String, Date >>, i just can't write it here (it disappears).

asked 16 Apr, 11:43

noelo's gravatar image

noelo
102
accept rate: 0%


All you need it to get a month from date and remove date if it summer month.

public class Solution
{
    public static HashMap<String, Date> createMap()
    {
        HashMap<String, Date> map = new HashMap<String, Date>();
        map.put("Stallone", new Date("JUNE 1 1980"));
        map.put("Stallone1", new Date("JANUARY 1 1980"));
        map.put("Stallone3", new Date("FEBRUARY 1 1980"));
        map.put("Stallone4", new Date("MARCH 1 1980"));
        map.put("Stallone5", new Date("APRIL 1 1980"));
        map.put("Stallone6", new Date("JUNE 1 1980"));
        map.put("Stallone7", new Date("JULY 1 1980"));
        map.put("Stallone8", new Date("AUGUST 1 1980"));
        map.put("Stallone9", new Date("SEPTEMBER 1 1980"));
        map.put("Stallone10", new Date("NOVEMBER 1 1980"));
        return map;
    }

    public static void removeAllSummerPeople(HashMap<String, Date> map)
    {
        SimpleDateFormat date = new SimpleDateFormat("MM");
        Iterator <Map.Entry<String, Date>> it = map.entrySet().iterator();
        while(it.hasNext()){
            Map.Entry<String, Date> element = it.next();
            if(Integer.parseInt(date.format(element.getValue().getTime())) > 5 && Integer.parseInt(date.format(element.getValue().getTime())) < 9){
                it.remove();
            }
        }
    }
}
link

answered 26 May, 12:30

Igor's gravatar image

Igor
112
accept rate: 0%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×10

Asked: 16 Apr, 11:43

Seen: 112 times

Last updated: 26 May, 12:30