Do Java arrays have a maximum size?

前端 未结 9 2126
礼貌的吻别
礼貌的吻别 2020-11-21 11:51

Is there a limit to the number of elements a Java array can contain? If so, what is it?

相关标签:
9条回答
  • 2020-11-21 12:10

    There are actually two limits. One, the maximum element indexable for the array and, two, the amount of memory available to your application. Depending on the amount of memory available and the amount used by other data structures, you may hit the memory limit before you reach the maximum addressable array element.

    0 讨论(0)
  • 2020-11-21 12:16

    Yes, there limit on java array. Java uses an integer as an index to the array and the maximum integer store by JVM is 2^32. so you can store 2,147,483,647 elements in the array.

    In case you need more than max-length you can use two different arrays but the recommended method is store data into a file. because storing data in the file has no limit. because files stored in your storage drivers but array are stored in JVM. JVM provides limited space for program execution.

    0 讨论(0)
  • 2020-11-21 12:18

    Maximum number of elements of an array is (2^31)−1 or 2 147 483 647

    0 讨论(0)
提交回复
热议问题