Java - Core Java - Jagged Array

Jagged Array

Jagged array is an array of arrays such that member arrays can be of different sizes. We can create a 2D arrays but with variable number of columns in each row. These types of arrays are also known as Jagged arrays.

Program for jagged array
class JaggedArray
    public static void main(String[] args)
        // Declaring 2D array with 2 rows
        int arr[][] = new int[2][];
        // Making the above array Jagged, first row has 3 columns
        arr[0] = new int[3];
        // Second row has 2 columns
        arr[1] = new int[2];
        // Initializing array
        int count = 0;
        for (int i=0; i
Elements of 2D jagged array
0 1 2
3 4