Java Collection Tutorial - Java Collections .disjoint ( Collection <?> c1, Collection <?> c2)








Syntax

Collections.disjoint(Collection <?> c1, Collection <?> c2) has the following syntax.

public static boolean disjoint(Collection <?> c1,   Collection <?> c2)

Example

In the following code shows how to use Collections.disjoint(Collection <?> c1, Collection <?> c2) method.

//w ww.jav  a  2 s.c o m
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Main {
   public static void main(String args[]) {
 
      List<String>  srclst = new ArrayList<String> (5);
      List<String>  destlst = new ArrayList<String> (10);
      
      // populate two lists
      srclst.add("tutorial");
      srclst.add("from");
      srclst.add("java2s.com");
      
      destlst.add("Java Tutorial");
      destlst.add("from");
      destlst.add("java2s.com");      
      
      // check elements in both collections
      boolean iscommon = Collections.disjoint(srclst, destlst);
      
      System.out.println("No commom elements: "+iscommon);    
   }    
}

The code above generates the following result.