I want syntax for creating 2d ArrayList and how to take input in it one by one.
ArrayList<ArrayList<Integer>> list = new ArrayList<>();
Is this syntax is right?
I want syntax for creating 2d ArrayList and how to take input in it one by one.
ArrayList<ArrayList<Integer>> list = new ArrayList<>();
Is this syntax is right?
Yes, Your syntax is absolutely right. You can take input using Scanner class. Let me brief you an example.
Scanner scanner=new Scanner(System.in);
int row = scanner.nextInt();
int col = scanner.nextInt();
ArrayList<Integer> list=null;
for (int j = 0; j < row; j++) {
for (int i = 0; i < col; i++) {
list = new ArrayList<>();
list.add(scanner.nextInt());
}
ArrayList<ArrayList<Integer>> lists = new ArrayList<>();
lists.add(list);
}
Try this out. Hope it works :)