Remove element from List

ReturnMethodSummary
Eremove(int index)Removes the element at the specified position in this list (optional operation).
booleanremove(Object o)Removes the first occurrence of the specified element from this list, if it is present (optional operation).
boolean removeAll(Collection<?> c) Removes from this list all of its elements that are contained in the specified collection (optional operation).
boolean retainAll(Collection<?> c) Retains only the elements in this list that are contained in the specified collection (optional operation).

import java.util.ArrayList;
import java.util.List;

public class Main {
  public static void main(String[] args) {
    List list = new ArrayList();

    list.add("1");
    list.add("2");
    list.add("3");

    list.add("java2s.com");

    System.out.println(list);

    list.remove("java2s.com");
    
    System.out.println(list);
    
  }
}

The output:


[1, 2, 3, java2s.com]
[1, 2, 3]
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.