package collection.demos;
import java.util.ArrayList;
import java.util.Collections;
public class TestingDisjointInCollections{
public static void main(String[] args) {
ArrayList<String> list1 = new ArrayList<String>();
list1.add("A");
list1.add("B");
list1.add("C");
ArrayList<String> list2 = new ArrayList<String>();
list2.add("D");
list2.add("E");
list2.add("F");
ArrayList<String> list3 = new ArrayList<String>();
list3.add("A");
list3.add("B");
list3.add("C");
System.out.println("List1 and list2 have no common elements in collection : "+Collections.disjoint(list1, list2));
System.out.println("List1 and list3 have no common elements in collection : "+Collections.disjoint(list1, list3));
}
}
/*
OUTPUT :
List1 and list2 have no common elements in collection : true
List1 and list3 have no common elements in collection : false
*/
import java.util.ArrayList;
import java.util.Collections;
public class TestingDisjointInCollections{
public static void main(String[] args) {
ArrayList<String> list1 = new ArrayList<String>();
list1.add("A");
list1.add("B");
list1.add("C");
ArrayList<String> list2 = new ArrayList<String>();
list2.add("D");
list2.add("E");
list2.add("F");
ArrayList<String> list3 = new ArrayList<String>();
list3.add("A");
list3.add("B");
list3.add("C");
System.out.println("List1 and list2 have no common elements in collection : "+Collections.disjoint(list1, list2));
System.out.println("List1 and list3 have no common elements in collection : "+Collections.disjoint(list1, list3));
}
}
/*
OUTPUT :
List1 and list2 have no common elements in collection : true
List1 and list3 have no common elements in collection : false
*/
Comments