-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharrList.java
More file actions
47 lines (35 loc) · 1.34 KB
/
arrList.java
File metadata and controls
47 lines (35 loc) · 1.34 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import java.util.ArrayList;
public class arrList{
public static void main(){
// resizable one-Dimensional
ArrayList<String> food = new ArrayList<String>();
food.add("Pizza");
food.add("burger");
food.add("puri");
food.set(0, "kheer");
food.remove(1);
food.clear();
for(int i = 0; i<food.size(); i++){
System.out.println(food.get(i));
}
// TWO DIMENSIONAL ARRAYS
ArrayList<String> bakeryList = new ArrayList();
bakeryList.add("Pasta");
bakeryList.add("Maggie");
bakeryList.add("Pan Cakes");
ArrayList<String> produceList = new ArrayList();
produceList.add("Tomatoes");
produceList.add("Peppers");
produceList.add("Dhaniya");
ArrayList<String> drinksList = new ArrayList();
drinksList.add("Mirinda");
drinksList.add("Limca");
ArrayList<ArrayList<String>> groceryList = new ArrayList();
groceryList.add(bakeryList);
groceryList.add(produceList);
groceryList.add(drinksList);
System.out.println(groceryList);
System.out.println(groceryList.get(1).get(2));
System.out.println(groceryList.get(2).get(0));
}
}