Multi Dimensional Array in Java

Multidimensional arrays are array that contain other arrays. The two-dimensional array is the most basic multidimensional array. Placing each array within its own set of square brackets. We have two arrays in the code, so res= [1][0] means: choose second array list and select the first string with array position of 0.

Source code :

public class MutiArr {
    public static void main(String[] args) {
        /*Creates two-dimensional array &
        assigning variable name to arrays */
        String [ ][ ] names = { {"apple","orange","grapes"}, {"nameOne","nameTwo","nameThree"} };
        String  res = names[1][0]; #position of string
        String res1 = names[0][0];

Output :


Notes :

  • You can add many arrays as much you want.
  • Array index is zero-based.

Output :


Comments :