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






ArrayList: retainAll(Collection c)

  
/*
 Output:


true
[2nd, 3rd, 2nd, 3rd]


 * */

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

public class MainClass {
  public static void main(String args[]) {
    String orig[] = { "1st", "2nd", "3rd", "4th", "5th", "1st", "2nd", "3rd",
        "4th", "5th" };
    String act[] = { "2nd", "3rd", "6th" };
    List origList = new ArrayList(Arrays.asList(orig));
    List actList = Arrays.asList(act);

    System.out.println(origList.retainAll(actList));
    System.out.println(origList);
  }
}
           
         
    
  








Related examples in the same category

1.new ArrayList < E > ()
2.new ArrayList(Collection c)
3.ArrayList: add(E o)
4.ArrayList: add(int index, E element)
5.ArrayList: addAll(Collection c)
6.ArrayList: addAll(int index, Collection c)
7.ArrayList: clear()
8.ArrayList: contains(Object elem)
9.ArrayList: equals(Object o)
10.ArrayList: ensureCapacity(int minCapacity)
11.ArrayList: get(int index)
12.ArrayList: indexOf(Object elem)
13.ArrayList: isEmpty()
14.ArrayList: iterator()
15.ArrayList: lastIndexOf(Object o)
16.ArrayList: listIterator()
17.ArrayList: remove(int index)
18.ArrayList: remove(Object o)
19.ArrayList: removeAll(Collection c)
20.ArrayList: set(int index, T element)
21.ArrayList: size()
22.AbstractList: subList(int fromIndex, int toIndex)
23.ArrayList: toArray()
24.ArrayList: toArray(T[] a)
25.ArrayList: trimToSize()
26.for each loop for ArrayList