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/int` values is going to take up a certain amount of memory no matter what data structure you use - for 100 million values, 400 MB forints and 800 MB forlongs. An array is pretty much as lean as you can get