title: Java Out of Memory Array Error
body: <p>I'm trying to store a large amount of longs into an array, but I get an OOM error with my array and ArrayList.</p>
  
  <pre><code>    ArrayList&lt;Long&gt; A = new ArrayList&lt;Long&gt;();
      Long[] B = new Long[100000000];
  
      for(int i = 0; i &lt; 100000000; i++) A.add(i);        
      for(int i = 0; i &lt; 100000000; i++) B[i] = (long) i;
  
  //Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
  //at java.lang.Integer.valueOf(Unknown Source)
  </code></pre>
  
  <p>Is there any other simple data structure I can use to store such a large amount of longs or integers?</p>