List: retainAll(Collection c) : List « java.util « Java by API






List: retainAll(Collection c)

 


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

public class Main {
  public static void main(String[] argv) throws Exception {
    List<String> list1 = new ArrayList();
    List<String> list2 = new ArrayList();

    list1.addAll(list2);

    list1.removeAll(list2);

    list1.retainAll(list2);

    list1.clear();

    int newSize = 2;
    list1.subList(newSize, list1.size()).clear();
  }
}

   
  








Related examples in the same category

1.List: add(T e)
2.List: addAll(Collection c)
3.List: clear()
4.List: clone()
5.List: contains(Object o)
6.List: equals(Object o)
7.List: get(int index)
8.List: isEmpty()
9.List: iterator()
10.List: lastIndexOf(Object o)
11.List: listIterator()
12.List: remove(int index)
13.List: remove(Object o)
14.List: removeAll(Collection c)
15.List: set(int index, T element)
16.List: subList(int fromIndex, int toIndex)
17.List: toArray(T[] a)