Does Java support multi-dimensional arrays?

No, Java does not support two or multi-dimensional arrays in the same way C and C++ do. In Java each row of a two-dimensional array is itself a one-dimensional array. Many programming languages directly support two dimensional arrays, but in Java a two dimensional array is an array of references to array objects. Because in Java a two-dimensional array is an array of one-dimensional arrays; therefore, rows of a seemingly two-dimensional array are allowed to vary in length.

A two-dimensional array variable is declared in exactly the same way as a one-dimensional array variable, except that there are two pairs of square brackets.

The following piece of code declares a two-dimensional array twoDimArr of type double.

double [][] twoDimArr;
twoDimArr = new double[10][10];

The first dimension specifies the number of rows, and the second dimension specifies the number of columns. To access an individual component of the twoDimArr array we have to specify its position in form of row and column expressions. We place each expression in its own pair of brackets next to the name of the array. For example, twoDimArr[1][1] points to second element of the second row in the array.

Hope you have enjoyed reading about support of multi-dimensional arrays in Java. Please do write us your suggestions/comments to improve this page. Thanks for reading!



Get Free Tutorials by Email

About the Author

is the main author for cs-fundamentals.com. He is a software professional (post graduated from BITS-Pilani) and loves writing technical articles on programming and data structures.

Today's Tech News

Plans drawn up for world's tallest wooden skyscraperPosted on Monday February 19, 2018

The 70-storey tower would be 90% wood and have trees and other foliage on every level.

Probe after 'drone made helicopter crash'Posted on Monday February 19, 2018

Investigations are launched after a helicopter reportedly crashed after swerving to avoid a consumer drone.

Dark web paedophile Matthew Falder jailed for 32 yearsPosted on Monday February 19, 2018

Matthew Falder blackmailed victims into sending sexual images that he then shared on the dark web.

Courtesy BBC News

AD BLOCKER DETECTED!

Advertisements help running this site for free.


To view the content please disable AdBlocker and refresh the page.

×