- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayListMagnet.java
More file actions
Latest commit
34 lines (30 loc) · 601 Bytes
/
Copy pathArrayListMagnet.java
File metadata and controls
34 lines (30 loc) · 601 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
importjava.util.*;
publicclassArrayListMagnet{
publicstaticvoidmain(String[] args){
ArrayList<String> a = newArrayList<String>() ;
a.add(0,"zero");
a.add(1,"one");
a.add(2,"two");
a.add(3,"three");
printAL(a);
a.remove(2);
if (a.contains("two")) {
a.add("2.2");
}
if (a.contains("three")) {
a.add("four");
}
printAL(a);
if (a.indexOf("four") != 4){
a.add(4,"4.2");
}
printAL(a);
printAL(a);
}
publicstaticvoidprintAL(ArrayList<String> al) {
for (Stringelement: al){
System.out.print(element + " ");
}
System.out.println(" ");
}
}