Hello guys,
So here we are, on one hand Iterators. I can easily say to my mind that an iterator is by definition something usefull for Maps ,Lists and Sets. And i also know that we can't modify a Map or a Set during a normal for each loop. But that's all i know, so i go on the Java Doc
On the other hand, Dates. When i first try to implement something like myDate.getMonth i had an alert from Intelijj that this method is deprecated, i should use a Calendar.
Ok that's fine, my first reflex was to go on the Java Doc.
For these situations, i was so lost in the Java Doc and can't figure out by myself what i should look for: Iterator (how to iterate trought a Map ?) and Calendar (How to get a calendar date from a Date, and work with the Month).
So the second reflex was to google my "How to" and land in Stack Overflow, where everything is explain clearly by pros .
I implement the solution, and it's work.
But an imposter syndrome came to my mind and i don't know if it's the same for you but i feel bad to not find in the doc a simply explanation about my asks. I have the feeling that you have to know the existing methods to appreciate the Java Doc.
I'm asking to experienced developer, what's your way to find this kind of informations i'm sure you asking to yourself sometimes ("Oh ok, i have to work with Calendar and a Date, let's search in java doc").
What is your routine to find informations in Java doc like these ?
Is it normal in our ages to find solutions in Stack Overflow ?
Thanks a lot guys. Happy Coding !
package com.codegym.task.task08.task0816;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
/*
Kind Emma and the summer holidays
*/
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"));
map.put("Bill", df.parse("FEBRUARY 1 1980"));
map.put("Franc", df.parse("JANUARY 1 1980"));
map.put("Burt", df.parse("JUNE 1 1980"));
map.put("sdk", df.parse("JUNE 1 1980"));
map.put("sdlkjsd", df.parse("JULY 1 1980"));
map.put("dflijh", df.parse("FEBRUARY 1 1980"));
map.put("uihdjvb", df.parse("JUNE 1 1980"));
map.put("mdne", df.parse("JANUARY 1 1980"));
map.put("Ssdtllone", df.parse("OCTOBER 1 1977"));
return map;
}
public static void removeAllSummerPeople(HashMap<String, Date> map) {
Calendar calendar = Calendar.getInstance(); // Date.getMonth is deprecated, we use Calendar;
Iterator<Map.Entry<String, Date>> itr = map.entrySet().iterator();
while (itr.hasNext()) {
Map.Entry<String, Date> entry = itr.next();
calendar.setTime(entry.getValue());
int month = calendar.get(Calendar.MONTH); // Month from 0 to 11
if (month >= 5 && month < 8) {
itr.remove();
}
}
}
public static void main(String[] args) throws ParseException {
HashMap<String, Date> map = createMap();
removeAllSummerPeople(map);
for (Map.Entry<String, Date> entry : map.entrySet()) {
System.out.println(entry);
}
}
}