Java Collections Java Java API
Class:
java.util.Collections
Method:
public static boolean disjoint(Collection<?> c1,
Collection<?> c2)
Returns true if the two specified collections have no elements in common.
Examples
package com.logicbig.example.collections;
import java.util.Arrays; import java.util.Collections; import java.util.List;
public class DisjointExample {
public static void main(String... args) { List<Integer> list = Arrays.asList(1, 2, 3, 4); List<Integer> list2 = Arrays.asList(10, 20, 30, 40, 50, 60); boolean b = Collections.disjoint(list, list2); System.out.println(b); } }
Outputtrue
package com.logicbig.example.collections;
import java.util.Arrays; import java.util.Collections; import java.util.List;
public class DisjointExample2 {
public static void main(String... args) { List<Integer> list = Arrays.asList(1, 2, 3, 4); List<Integer> list2 = Arrays.asList(10, 20, 30, 4, 50, 60); boolean b = Collections.disjoint(list, list2); System.out.println(b); } }
Outputfalse
|
|