What is the maximum number of dimensions allowed in a Java array?

The story behind the answer

The maximum number of dimensions allowed in a Java array is 255. This limit comes from the Java Virtual Machine's representation of array types and is independent of how much memory the array consumes.

Java arrays are technically objects, and multidimensional arrays are arrays whose elements can themselves be arrays. For example, int[][] is an array of int[] references, while int[][][] adds another level. Java does not require every row in a multidimensional array to have the same length, so these structures can be jagged rather than rectangular.

The 255 limit is encoded in the JVM's array type descriptors and class-file constraints. The descriptor uses one opening bracket per dimension, and the specification permits no more than 255 dimensions. This is a type-system and bytecode limit, not a practical recommendation for application design.

A common trap is confusing dimensions with elements. An int[10][20] array has two dimensions and up to 200 primitive elements, while an array's practical size is usually constrained by heap memory, object overhead, and indexing limits long before 255 dimensions become useful. The distractor 256 exceeds the JVM limit by one.

Source: Wikipedia · fact-checked Aug. 2026

Add question to a list

Choose a list to keep this question in: