-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArraylists.java
More file actions
44 lines (38 loc) · 1.19 KB
/
Arraylists.java
File metadata and controls
44 lines (38 loc) · 1.19 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
import java.util.*;
public class Arraylists{
public static void main(String []args){
//1D Arraylist
/* ArrayList<String> food=new ArrayList<String>();
food.add("Meat");
food.add("Sushi");
food.add("Ramen");
food.add("MOMO");
food.set(0,"Chowmein");
food.remove(3);
for(int i=0;i<food.size();i++){
System.out.println(food.get(i));
}
food.clear();*/
//2D ArrayList
ArrayList<ArrayList<String>> school=new ArrayList<ArrayList<String>>();
ArrayList<Integer> marks=new ArrayList<Integer>();
marks.add(32);
marks.add(43);
marks.add(99);
System.out.println(marks);
ArrayList<String> sub=new ArrayList<String>();
sub.add("Math");
sub.add("Science");
sub.add("Chemistry");
System.out.println(sub);
ArrayList<String> stu=new ArrayList<String>();
stu.add("Mark");
stu.add("Harry");
stu.add("Chandu");
System.out.println(stu);
school.add(sub);
school.add(stu);
System.out.println(school);
System.out.println(school.get(1).get(2));
}
}