If the array is sparse, one option could be a Map
of index to value.
If all the data can still fit into memory, the index is just beyond the range of int
, you could consider an array of arrays. The primary array can contain arrays of size let's say 1000000000. The 0th index in this array would contain values 0-999999999, the 1st index, 1000000000-1999999999, etc.
Another alternative is using files. A RandomAccessFile
might help to do this manually, or there may be some libraries that give you an array interface and takes care of the file I/O behind the scenes.