-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathArrayList.java
More file actions
50 lines (34 loc) · 778 Bytes
/
ArrayList.java
File metadata and controls
50 lines (34 loc) · 778 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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import java.util.ArrayList;
import java.util.Collections;
public class Arraylist {
public static void main(String[] args) {
ArrayList<Integer> list =new ArrayList<Integer>();
//add
list.add(0);
list.add(3);
System.out.println(list);
//get
int element = list.get(1);
System.out.println(element);
//add element in between
list.add(1,5);
System.out.println(list);
//set
list.set(0,9);
System.out.println(list);
//remove
list.remove(0);
System.out.println(list);
//size
int size = list.size();
System.out.println(size);
//Loop
for(int i =0 ; i<list.size(); i++) {
System.out.print(list.get(i));
}
System.out.println();
//sorting
Collections.sort(list);
System.out.println(list);
}
}