Java array with more than 4gb elements

后端 未结 11 1872
心在旅途
心在旅途 2020-11-27 07:06

I have a big file, it\'s expected to be around 12 GB. I want to load it all into memory on a beefy 64-bit machine with 16 GB RAM, but I think Java does not support byte arra

11条回答
  •  囚心锁ツ
    2020-11-27 07:49

    As others have said, all Java arrays of all types are indexed by int, and so can be of max size 231 − 1, or 2147483647 elements (~2 billion). This is specified by the Java Language Specification so switching to another operating system or Java Virtual Machine won't help.

    If you wanted to write a class to overcome this as suggested above you could, which could use an array of arrays (for a lot of flexibility) or change types (a long is 8 bytes so a long[] can be 8 times bigger than a byte[]).

提交回复
热议问题