0

How can I store more than 2^128 elements in an array in java.

I tried Integer.MAX_value but this is not the range I want. I want more numbers.

This is the ERROR in using (Integer.MAX_VALUE):

Exception in thread "main" java.lang.OutOfMemoryError: Requested array size exceeds VM limit.

Michael Mahn
  • 737
  • 4
  • 11

1 Answers1

0

In Java, arrays internally use integers (int not Integer) for index, the max size is limited by the max size of integers. So theoretically it is 2^31-1 = 2147483647, which is Integer.MAX_VALUE.

But in recent HotSpot JVM it has been observed that the max size of array can be Integer.MAX_VALUE - 5.

Istiaque Hossain
  • 2,157
  • 1
  • 17
  • 28