I work on a graph where I visualize my emails. I want to be able to get the emails from a certain day.
Is this a bad way to store?
HashMap<DateTime, ArrayList<Email>>
Or is it better to convert the date to a string and then use HashMap<String, ArrayList<Email>>
Note, the dates are added without hours, minutes and seconds, so just like 06/07/2010 for example.
DateTimehas properly definedequalsandhashcodemethods, so using those as the key in aHashMapis perfectly OK. There’s not much to be gained by converting them to strings first.I would suggest, however, that if you only want to store the year/month/day components, then you may want to use
LocalDateinstead ofDateTime.Additionally, you could also consider using
TreeMaprather thanHashMap, so that your map is automatically sorted by date. Might be handy.