-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path20_2dArrayList
More file actions
29 lines (23 loc) · 977 Bytes
/
20_2dArrayList
File metadata and controls
29 lines (23 loc) · 977 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
//2D Array List = Dynamic list of lists
//You can change the size of these lists during runtime
public class Main {
public static void main(String[] args) {
ArrayList<ArrayList<String>> groceryList = new ArrayList(); //To create 2D ArrayList
ArrayList<String> bakeryList = new ArrayList();
bakeryList.add("pasta");
bakeryList.add("garlic bread");
bakeryList.add("donuts");
ArrayList<String> produceList = new ArrayList();
produceList.add("tomatoes");
produceList.add("zucchini");
produceList.add("peppers");
ArrayList<String> drinksList = new ArrayList();
drinksList.add("soda");
drinksList.add("coffee");
groceryList.add(bakeryList); //To add list into list
groceryList.add(produceList);
groceryList.add(drinksList);
System.out.println(groceryList);
System.out.println(groceryList.get(0).get(0));//Get ? element in ? list
}
}