HashMap used to store DateTime I have a scenario where I need to save a string as a key and DateTime as value into a hash map. Also, I need to remove strings older than 24 hours.

At the moment the HashMap is implemented as below:

HashMap&lt;String, DateTime&gt; sessions = new HashMap&lt;&gt;();
//Adding to the HashMap
sessions.put(session.toString(), DateTime.now());
//Removing from the HashMap
sessions.forEach((str, time)-&gt; {
    if(time.clicks() &lt; DateTime.now().minus(86400000).clicks())
        sessions.remove(str);
});


Would it be less overhead to save the DateTime clicks as Long datatype rather than saving the whole DateTime object? Like below:

HashMap&lt;String, Long&gt; sessions = new HashMap&lt;&gt;();
//Adding to the HashMap
sessions.put(session.toString(), DateTime.now().clicks);
//Removing from the HashMap
sessions.forEach((str, time)-&gt; {
    if(time &lt; DateTime.now().minus(86400000).clicks())
        sessions.remove(str);
});
I'll go out on a limb and say most senior developers would discourage any form of datetime arithmetic involving raw numbers rather than DateTime objects. There are a whole heap of problems you can avoid (leap years, leap seconds, timezone changes etc.) by always using datetime objects rather than timestamps. See for example Falsehoods programmers believe about time. In short, the potential for bugs completely outweighs the tiny memory savings.