What is the maximum number of elements a Java array can hold?

The story behind the answer

The maximum theoretical number of elements in a Java array is 2,147,483,647, or 2³¹ − 1.

That limit comes from Java’s use of the signed 32-bit `int` type for array indexes and lengths. A length of `n` permits indexes from 0 through `n − 1`, so the largest representable positive length is `Integer.MAX_VALUE`, which equals 2,147,483,647. The next value, 2,147,483,648, is outside the positive range of `int`.

This is a language and indexing limit, not a promise that every computer can actually allocate such an array. A JVM may impose a slightly smaller implementation limit, and the available heap, object headers, garbage collector, address space, and element size usually make enormous arrays impractical. Creating one without enough memory commonly results in `OutOfMemoryError`.

The restriction applies to each array dimension separately. A multidimensional Java array is really an array of array references, so its dimensions do not form one flat guaranteed capacity. Java also has no growable built-in array; collections such as `ArrayList` provide resizing behavior instead.

Source: Wikipedia · fact-checked Aug. 2026

Add question to a list

Choose a list to keep this question in: