- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArraryListMagnet.java
More file actions
Latest commit
45 lines (37 loc) · 733 Bytes
/
Copy pathArraryListMagnet.java
File metadata and controls
45 lines (37 loc) · 733 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
importjava.util.*;
publicclassArraryListMagnet
{
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("three"))
{
a.add("four");
}
printAL(a);
if (a.indexOf("four") != 4 )
{
a.add(4, "4.2");
}
printAL(a);
if (a.contains("two"))
{
a.add("2.2");
}
printAL(a);
}
publicstaticvoidprintAL(ArrayList<String> al)
{
for (Stringelement : al)
{
System.out.print(element + " ");
}
System.out.println(" ");
}
}