I'm trying to store a large amount of longs into an array, but I get an OOM error with my array and ArrayList.
ArrayList<Long> A = new ArrayList<Long>();
Long[] B = new Long[100000000];
for(int i = 0; i < 100000000; i++) A.add(i);
for(int i = 0; i < 100000000; i++) B[i] = (long) i;
//Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
//at java.lang.Integer.valueOf(Unknown Source)
Is there any other simple data structure I can use to store such a large amount of longs or integers?
Long
is not terribly large. To set heap size limit, use "-Xmx" java command line option. Reference: http://docs.oracle.com/javase/7/docs/technotes/tools/windows/java.html – James Jun 30 '14 at 22:25