Java List remove elements from another List/Collection

Description

Java List remove elements from another List/Collection


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

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

    List<String> list = new ArrayList<>();
    list.add("CSS");
    list.add("CSS");
    list.add("HTML");
    list.add("HTML");
    list.add("Java");
    list.add("Java");
    System.out.println(list);// w w w  .  j a v  a  2 s.c o  m
    

    List<String> list2 = new ArrayList<>();
    list2.add("CSS");
    list2.add("HTML");
    list2.add("Java");
    list.removeAll(list2);

    System.out.println(list);
  }
}



PreviousNext

Related