title: Map alternative for primitive values
body: <p>I did some profiling on my application and one of the results turned out that about 18% of memory on the heap is used by objects of type <code>Double</code>. It turns out these objects are the values in <code>Map</code>s, where I cannot use the primitive type.</p>
  
  <p>My reasoning is that the primitive type of <code>double</code> consumes less memory than it's object <code>Double</code>. Is there a way to have a map like data structure, that would accept any type as key and a primitive <code>double</code> as values?</p>
  
  <p>Main operations would be:</p>
  
  <ul>
  <li>insertion (probably only once)</li>
  <li>Lookup (contains by key)</li>
  <li>Retrieval (by key)</li>
  <li>Iteration</li>
  </ul>
  
  <p>Typical maps that I have are:</p>
  
  <ul>
  <li><code>HashMap&lt;T, HashMap&lt;NodeData&lt;T&gt;, Double&gt;&gt; graph</code></li>
  <li><code>HashMap&lt;Point2D, Boolean&gt; onSea</code> (though not a double value)</li>
  <li><code>ConcurrentHashMap&lt;Point2D, HashMap&lt;Point2D, Double&gt;&gt;</code></li>
  </ul>
  
  <p>All used with Java 8.</p>
  
  <p><strong>Addendum</strong></p>
  
  <p>I am mainly not interested in frameworks that have a solution to these type of maps, but on what has to be considered when addressing these issues. If you want, what are the concepts/ideas/approaches behind any such framework. Or the solution may be also on another level, where the maps are replaced with objects following a certain pattern like @Ilmari Karonen pointed out in his answer.</p>