Although obvious by the code, but maybe the above comments should be adjusted.al.add("charlie"); //insert an object
al.add(2, "david"); //remove an object
al.remove(0); //process the objects
Also, a side question to different part of the same code segment,
given the above code,for(Object o : al){
String name = (String) o;
System.out.println(name+" "+name.length());
}
1. Why the following causes compiler error "variable declaration not allowed here" only when no brackets are present.
2. while, as expected, the following causes no compiler error with or without brackets.for(Object o : al)
String name = (String) o;
ThanksString name = " ";
for(Object o : al)
System.out.println(name+" "+name.length());