What is a Multidimensional array in Java?


In Java, a multi-dimensional array is nothing but an array of arrays.

2D array − A two-dimensional array in Java is represented as an array of one-dimensional arrays of the same type. Mostly, it is used to represent a table of values with rows and columns −

Int[][] myArray = {{10, 20, 30}, {11, 21, 31}, {12, 22, 32} }


In short, a two-dimensional array contains one-dimensional arrays of elements. It is represented by two indices where the first index denotes the position of the array and the second index represents the position of the element within that particular array −


Example

public class Tester {
   public static void main(String[] args) {
      int[][] multidimensionalArray = { {1,2},{2,3}, {3,4} };
     
      for(int i = 0 ; i < 3 ; i++){
         //row
         for(int j = 0 ; j < 2; j++){
            System.out.print(multidimensionalArray[i][j] + " ");
         }
         System.out.println();
      }
   }
}    

Output

1 2
2 3
3 4    

Monica Mona
Monica Mona

Student of life, and a lifelong learner

Updated on: 07-Mar-2024

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements