Retain elements collection c has

ReturnMethodSummary
boolean retainAll(Collection<?> c) Retains only the elements in this Vector that are contained in the specified Collection.

import java.util.Arrays;
import java.util.Enumeration;
import java.util.Vector;

public class Main{

  public static void main(String args[]) {

    Vector v = new Vector();

    v.add("java2s.com");
    v.add("A");
    v.add("B");
    
    Vector v2 = new Vector();

    v2.add("java2s.com");
    v2.add("C");
    v2.add("D");
    
    v.retainAll(v2);
    System.out.println(v);
  }
}

The output:


[java2s.com]
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.