-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathListInterfaceExample.java
More file actions
66 lines (36 loc) · 1.68 KB
/
ListInterfaceExample.java
File metadata and controls
66 lines (36 loc) · 1.68 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import java.util.List;
import java.util.ArrayList;
public class ListInterfaceExample {
public static void main(String[] args) {
List<Integer> list = new ArrayList<>();
list.add(10);
list.add(20);
list.add(30);
list.add(40);
list.add(50);
System.out.println("Original List: " + list);
list.add(0, 5);
System.out.println("After inserting 5 at the start: " + list);
list.add(60);
System.out.println("After inserting 60 at the end: " + list);
list.add(2, 15);
System.out.println("After inserting 15 at index 2: " + list);
System.out.println("Element at index 3: " + list.get(3));
list.set(3, 25);
System.out.println("After updating element at index 3 to 25: " + list);
list.remove(0);
System.out.println("After removing element at the start: " + list);
list.remove(list.size() - 1);
System.out.println("After removing element at the end: " + list);
list.remove(3);
System.out.println("After removing element at index 3: " + list);
list.remove(Integer.valueOf(20));
System.out.println("After removing element with value 20: " + list);
boolean contains30 = list.contains(30);
System.out.println("List contains 30: " + contains30);
int size = list.size();
System.out.println("Size of the List: " + size);
list.clear();
System.out.println("After clearing the List: " + list);
}
}