❮ Previous Next ❯

Multi-Dimensional Array

The array taking more than one subscripts is known as multi-dimensional array.
Multidimensional arrays are represented in the form of array of array with each element of the array holding the reference of other array. These are also known as Jagged Arrays. A multidimensional array is created by appending one set of square brackets ([]) per dimension. Examples:


int[][] arr = new int[10][20]; //a 2D array
int[][][] arr = new int[10][20][10]; //a 3D array
MultiDimensionalDemo.java

class MultiDimensionalDemo
{
    public static void main(String[] args)
    {
        // declaring and initializing 2D array
        Int[][] arr = { {1,2,3},{4,5,6},{7,8,9} };

        // printing 2D array
        for (int i=0; i< 3 ; i++)
        {
            for (int j=0; j < 3 ; j++)
                System.out.print(arr[i][j] + " ");

            System.out.println();
        }
    }
}

Output

1 2 3 
4 5 6 
7 8 9 

❮ Previous Next ❯

Follow Us




  Tutorials

Popular Links

Contact Us

address Plot No-741,2ND Floor
Opp. Bhagabati Temple,Jayadev Vihar
      Bhubaneswar-751013
      Email: info@silantechnology.com
      Phone: 0674-2361252
address
39877, sundale dr, apt#101, Fremont, California 94538, USA
       Phone: +1(262)388-7619

facebook twitter google linked in

© 2018 Silan Technology. All Rights Reserved