Java supports arrays with 1 billion items. But such an array would consume 4 GB of memory which is probably above the default maximum heap size which depends on the OS and Java version and the available amount of memory.
You can set the maximum heap size with the
-Xmx
option. But it should not exceed the amount of available memory. So you might try for example
-Xmx5g
when you have at least 8 GB of RAM installed in your system. See also
Tuning Java Virtual Machines (JVMs)[
^].