0

How many integers can an array in java and python have? And if I want to enter more integers to an array and I reached that limit how to handle this?

Ahmed Sami
  • 21
  • 3
  • 2
    Java: http://stackoverflow.com/q/3038392/715593 – Ahmed Khalaf Mar 12 '16 at 17:26
  • You know, answering this question with google needs probably less time than you spent writing up the question ... just keep in mind that there are many "basic" things around; and you should get used to dig into existing material yourself. – GhostCat Mar 12 '16 at 17:27
  • Side note: if you have to deal with more than 2^31 elements, maybe an array isn't automatically the best data structure to use. I guess then you might want to consider a data structure that is optimized for the kind of computation you want to do. – GhostCat Mar 12 '16 at 17:31
  • This is actually *two* questions. One about java and the other about python. I'm calling this a dupe for java. Search/ask another about python if you want the answer for that language. – Bohemian Mar 12 '16 at 17:33

1 Answers1

0

Java arrays can have 2^31-1 element in theory, although some JVM cannot allocate an object larger than 2^31-8 elements due to OS limitations. (See the ArrayList code for an example of this limit in practice)

If you have more elements, you can either

  • have an array of arrays.
  • use a memory mapped file to store the data. This has the advantage of potentially greater than main memory and is persisted.
Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130