title: Delete oldest objects from HashMap to reach certain size?
body: <p>I have a hashmap in Java that I need to limit in size (order of 50000). But I should delete only items that are the oldest. The timestamp of the item is stored in the entry object's field:</p>
  
  <pre><code>Map&lt;String, MyModel&gt; snapshot = new  HashMap&lt;&gt;();
  </code></pre>
  
  <p>and </p>
  
  <pre><code>public class MyModel { 
      private ZonedDateTime createdAt;
      // other fields...
  }
  </code></pre>
  
  <p>I also insert them into the map in order by that timestamp.</p>
  
  <p>What would be the most effective way to accomplish this kind of deletion of oldest entries? Note that "threshold" in time is not known, only the desired final size of the Map.</p>