Collection: retainAll(Collection c) Removes from this collection every element that is not in c : Collection « Utility Classes « SCJP

Home
SCJP
1.Java Source And Data Type
2.Operators
3.Modifiers
4.Type Casting
5.Statements
6.Object Oriented
7.Thread
8.Utility Classes
9.File
SCJP » Utility Classes » Collection 
8.11.11.Collection: retainAll(Collection c) Removes from this collection every element that is not in c
import java.util.ArrayList;
import java.util.Collection;

public class MainClass {
  public static void main(String[] argv) {
    Collection c = new ArrayList();
    c.add("1");
    c.add("2");
    c.add("3");

    Collection c1 = new ArrayList();
    c1.add("1");

    c.retainAll(c1);

    System.out.println(c);

  }
}
[1]
8.11.Collection
8.11.1.The central interfaces of he Collections Framework are
8.11.2.Collection: add(Object x) Adds x to this collection
8.11.3.Collection: addAll(Collection c) Adds every element of c to this collection
8.11.4.Collection: clear() Removes every element from this collection
8.11.5.Collection: contains(Object x) Returns true if this collection contains x
8.11.6.Collection: containsAll(Collection c) Returns true if this collection contains every element of c
8.11.7.Collection: isEmpty() Returns true if this collection contains no elements
8.11.8.iterator() Returns an Iterator over this collection (see below)
8.11.9.Collection: remove(Object x) Removes x from this collection
8.11.10.Collection: removeAll(Collection c) Removes every element in c from this collection
8.11.11.Collection: retainAll(Collection c) Removes from this collection every element that is not in c
8.11.12.Collection: size() Returns the number of elements in this collection
8.11.13.Collection: toArray() Returns an array containing the elements in this collection
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.