개발 및 관리/Java
Head First Java - p.191 ArrayList6
HighLighter
2013. 1. 19. 00:54
반응형
// Head First Java p.191
import java.util.*;
class ArrayList6 {
public static void main(String[] args) {
ArrayList<String> a = new ArrayList<String>();
a.add(0, "zero");
a.add(1, "one");
a.add(2, "two");
a.add(3, "three");
printAL(a);
if (a.contains("three")) {
a.add("four");
}
a.remove(2);
printAL(a);
if (a.indexOf("four") != 4) {
a.add(4, "4.2");
}
printAL(a);
if (a.contains("two")) {
a.add("2.2");
}
printAL(a);
}
public static void printAL(ArrayList<String> al) {
for(int z = 0; z < al.size(); z++) {
System.out.print(z + "=" + al.get(z));
System.out.print(", ");
}
System.out.println(" ");
}
}
반응형