Online Java Compiler By
JavaTpoint.com
import java.util.*; public class CollectionsDisjointExample1 { public static void main(String[] args) { //Create two lists List
list1 = new ArrayList
(5); List
list2 = new ArrayList
(10); //Add elements in both lists list1.add("Java"); list1.add("PHP"); list1.add("JavaScript"); list2.add("C++"); list2.add("C"); list2.add("C#"); //Check elements in both List //It returns true if no elements are common. boolean iscommon = Collections.disjoint(list1, list2 ); System.out.println("Output: "+iscommon); } }
Output