Collection Interface containsAll() Method

Collection Interface containsAll() Method


Posted in : Java Posted on : November 25, 2010 at 11:40 AM Comments : [ 0 ]

Using this method we can check whether the elements exist or not in the invoking collection.

Collection Interface containsAll() Method:

Using this method we can check whether the elements exist or not in the invoking collection. Returns true if this collection contains all of the elements in the specified Collection. Otherwise  return false.

Syntax :

boolean containsAll(Collection c);

Example :

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

public class CollectionInterfaceContainsAllMethod{
public static void main(String[] args) {
  Collection collection = new ArrayList();
   collection.add(1);
   collection.add(2);
   collection.add(3);
   boolean result1 = collection.containsAll(collection);
   if(result1==true){
    System.out.println(collection);			
   }
   else{
    System.out.println("No any Element in the invoking collection.");
  }		
}
}

Output :

[1, 2, 3]

Download This example code

Go to Topic «PreviousHomeNext»

Your Comment:


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

 
Tutorial Topics