forked from dipsylocus/arraylist-pro
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinked list.java
More file actions
26 lines (26 loc) · 859 Bytes
/
Copy pathlinked list.java
File metadata and controls
26 lines (26 loc) · 859 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
mport java.util.*;
public class Main {
public static void main(String[] args) {
ArrayList<ArrayList<String>> groceryList = new ArrayList();
//CREATING 2D ARRAYLIST
ArrayList<String> bakeryList = new ArrayList();
//ARRAYLIST #1
bakeryList.add("pasta");
bakeryList.add("garlic bread");
bakeryList.add("donuts");
ArrayList<String> produceList = new ArrayList();
//ARRAYLIST #2
produceList.add("tomatoes");
produceList.add("zucchini");
produceList.add("peppers");
ArrayList<String> drinksList = new ArrayList();
//ARRAYLIST #3
drinksList.ad("soda");
drinksList.add("coffee");
groceryList.add(bakeryList);// ADDING #1#2#3 IN 2D ARRAYLIST
groceryList.add(produceList);
groceryList.add(drinksList);
System.out.println(groceryList);//WILL PRINT WHOLE 2D ARRAYLIST
System.out.println(groceryList.get(0).get(1));//WILL GET [0][1] ELEMENT
}
}