title: How to calculate HashMap memory usage in Java?
body: <p>I was asked in an interview to calculate the memory usage for <code>HashMap</code> and how much estimated memory it will consume if you have 2 million items in it. </p>
  
  <p>For example:  </p>
  
  <pre><code>Map &lt;String,List&lt;String&gt;&gt; mp=new HashMap &lt;String,List&lt;String&gt;&gt;();
  </code></pre>
  
  <p>The mapping is like this. </p>
  
  <pre><code>key   value
  ----- ---------------------------
  abc   ['hello','how']
  abz   ['hello','how','are','you']
  </code></pre>
  
  <p>How would I estimate the memory usage of this HashMap Object in Java?</p>