You cannot create an array in Java that is larger than the maximum positive int because the indices of the array are int . (The same goes for the various List implementations . You may be able to create one with a large number of entries [a LinkedList , for example], but things like get and size do not work correctly, you can only get later entries through iterator [ assuming things weren't just ordinary), which would take some time.)
It seems unlikely that you really need to create a boolean array with space for more than 2,147,483,647 entries, but if you really do, you will have to create several arrays and choose the right one, taking the module your index (which should be long ). (Or use some library other than the JDK, if one exists). It takes about 4 GB of RAM. Perhaps, but the chances are pretty high that a completely different approach would be better.
But 1,000,000,000,000 elements? This will require about 1-2 TB of RAM. As NPE says, if you donβt work on a supercomputer, you wonβt get it.
Tj crowder
source share