Java List remove element by value

Description

Java List remove element by value

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

public class Main {
  public static void main(String args[]) throws Exception {

    List<String> list = new ArrayList<String>();
    list.add("CSS");
    list.add("HTML");
    list.add("C++");
    list.add("Java");
    list.add("Javascript");
    list.add("SQL");
    list.add("Java");
    //from  w  w w . j  av a2  s  . co m

    System.out.println(list);
    
    //only remove one
    System.out.println(list.remove("Java"));
    System.out.println(list);

    //remove another one
    System.out.println(list.remove("Java"));
    System.out.println(list);

  }
}



PreviousNext

Related