Change c to ArrayList because:
Collection.remove (Object o)
Removes one instance of the specified item from this collection, if present (optional operation). More formally removes an element e such that (o == null? E == null: o.equals (e))
In the above example, if it was c.remove ("A"); he will work. Writing c.remove (1); Searches for the Integer object to be deleted.
ArrayList.remove (int index)
Deletes an item at the specified position in this list. Shifts any subsequent elements to the left (subtracts one of their indices).
So your program should be as follows:
public class Test{ public static void main(String[] args){ ArrayList c = new ArrayList(); c.add("A"); c.add("B"); c.add("C"); for(Iterator i = c.iterator(); i.hasNext();) System.out.println(i.next()); System.out.println(""); c.remove(1); c.remove(0); for(Iterator i = c.iterator(); i.hasNext();) System.out.println(i.next()); } }
source share