Remove from ArrayList

E remove(int index)
Removes the element at the specified position in this list.
booleanremove(Object o)
Removes the first occurrence of the specified element from this list, if it is present.

  import java.util.ArrayList;

public class MainClass {
    public static void main(String args[]) {
        ArrayList<String> al = new ArrayList<String>();

        System.out.println("Initial size of al: " + al.size());

        al.add("C");
        al.add("A");
        al.add("E");
        al.add("B");
        al.add("D");
        al.add("F");
        al.add(1, "A2");

        System.out.println("Size of al after additions: " + al.size());

        System.out.println("Contents of al: " + al);

        al.remove("F");
        al.remove(2);

        System.out.println("Size of al after deletions: " + al.size());
        System.out.println("Contents of al: " + al);
    }
}
  

The output:


Initial size of al: 0
Size of al after additions: 7
Contents of al: [C, A2, A, E, B, D, F]
Size of al after deletions: 5
Contents of al: [C, A2, E, B, D]
Home 
  Java Book 
    Collection  

ArrayList:
  1. ArrayList Class
  2. Create ArrayList object
  3. Add to ArrayList
  4. Clear an ArrayList
  5. Shallow copy of current ArrayList
  6. If contain a certain object
  7. Increases the capacity of an ArrayList
  8. Get/Replace element by index
  9. Get object for index
  10. Remove from ArrayList
  11. Get the size and trim to size
  12. If ArrayList is empty
  13. Convert ArrayList to array