1// Create dynamic 2d array in java
2import java.util.ArrayList;
3import java.util.List;
4public class Dynamic2dArray
5{
6 public static void main(String[] args)
7 {
8 List<int[]> li = new ArrayList<>();
9 li.add(new int[]{2,4,6});
10 li.add(new int[]{3,5});
11 li.add(new int[]{1});
12 // element at row 0, column 0
13 System.out.println("Element at [0][0]: " + li.get(0)[1]);
14 // get element at row : 1, column : 1
15 System.out.println("Element at [1][1]: " + li.get(1)[1]);
16 }
17}
1int** arr = new int*[10]; // Number of Students
2int i=0, j;
3for (i; i<10; i++)
4 arr[i] = new int[5]; // Number of Courses
5/*In line[1], you're creating an array which can store the addresses
6 of 10 arrays. In line[4], you're allocating memories for the
7 array addresses you've stored in the array 'arr'. So it comes out
8 to be a 10 x 5 array. */