title: Java Object Array null Element Memory
body: <p>Currently I'm using the following data structure:</p>
  
  <pre><code>MyObject[] arr = new MyObject[100]
  </code></pre>
  
  <p>now most of the fields in the Array are actually null (let's say 97%)</p>
  
  <p>As far as I can see the JVM reserves for each field the required memory for one instance of <code>MyObject</code> so a lot of memory is reserved even though it is never really used. </p>
  
  <p>Is there a way to save memory? Like only allocate the space for <code>MyObject</code> on demand? 
  Is there a better data structure then just a simple array? (needs to be both mem efficient and fast)</p>