Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How many array dimensions are supported in Java like a[1][1][1][1]....[1]? [duplicate]

How many array dimension is supported in Java like a[1][1][1][1]....[1]? Can I declare an unlimited number of dimensions for an array?

like image 938
kavai77 Avatar asked Mar 28 '14 12:03

kavai77


People also ask

How many dimensions can an array have in Java?

The Java language does not limit the number of dimensions, but the Java VM spec limits the number of dimensions to 255. (Ref: https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.4.1 "An array type descriptor is valid only if it represents 255 or fewer dimensions.")

Does Java support 3 dimensional array?

No, Java does not support multi-dimensional arrays.

How many dimensions can an array have?

More than Three Dimensions Although an array can have as many as 32 dimensions, it is rare to have more than three. When you add dimensions to an array, the total storage needed by the array increases considerably, so use multidimensional arrays with care.


1 Answers

The number of array dimensions are limited to 255.

The interesting thing is that there is no such limitation in Java programming language defined by JLS, but you can see in the JVM specification, that the array dimension is stored in 1 byte.

However, you can hardly meet this limitation on your day-to-day development. :-)

like image 194
kavai77 Avatar answered Oct 19 '22 07:10

kavai77