-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayListDemo.java
More file actions
72 lines (49 loc) · 1.26 KB
/
ArrayListDemo.java
File metadata and controls
72 lines (49 loc) · 1.26 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
67
68
69
70
71
72
import java.util.*;
public class ArrayListDemo {
public static void main(String[] args)
{
ArrayList al=new ArrayList();
al.add(10);
al.add(20);
al.add("Vikash");
al.add(10.25);
//int a=(int)al.get(0);
//System.out.println(a);
al.add(1, 25);
ArrayList al2=new ArrayList();
al2.add("A");
al2.add("B");
al2.add("C");
al2.add("D");
al.addAll(1, al2);
for(Object e1:al)
{
System.out.println("First Arraylist: "+e1);
}
//al2.clear();
System.out.println("Second Arraylist: "+al2);
boolean t=al.contains(10);
System.out.println(t);
boolean t1=al.containsAll(al2);
System.out.println(t1);
System.out.println(al2);
al2.set(1, "F");
System.out.println("After Replace: "+al2);
int i=al2.indexOf("C");
System.out.println("Index of C is: "+i);
al2.remove(2);
System.out.println("After removing single element: "+al2);
ArrayList al3=new ArrayList();
al3.add("A");
al3.add("G");
al3.add("H");
al3.add("K");
//al2.retainAll(al3);
//System.out.println(al2);
List al4=al3.subList(1, 2);
System.out.println(al4);
System.out.println("Before removeall(al2): "+al2);
al2.removeAll(al3);
System.out.println(al2);
}
}