You can get a hint by the fact that arrays are accessed using integer literals. Since integer literals only go up to Integer.MAX_VALUE
, that's how many indices (and elements) your array can have. arshajii brings up another hint.
Your problem just has to do with the fact that your application doesn't have enough memory to create that many long
s but has enough to create that many short
s. Remember that when an array is initialized, its elements are also initialized to a default value. For primitive types, that value is 0
or 0.0
. Things to consider (depending on your environment)
Long[] array = new Long[33554432]; // allocation would work
long[] array = new long[33554432]; // allocation would fail
This is because reference types are initialized to null
reference and so only the reference takes up space. So you could start adding elements, but it would also eventually fail.
Start your application with more memory.