Java Collections disjoint()方法

Java Collections disjoint()方法


集合类disjoint()方法 (Collections Class disjoint() method)

disjoint() method is available in java.util package.

disjoint()方法在java.util包中可用。

disjoint() method is used to check whether the given Collection objects may contain any common elements or not.

disjoint()方法用于检查给定的Collection对象是否可以包含任何公共元素。

disjoint() method is a static method, so it is accessible with the class name and if we try to access the method with the class object then we will not get an error.

disjoint()方法是一个静态方法,因此可以使用类名进行访问,如果尝试使用类对象访问该方法,则不会收到错误。

disjoint() method may throw an exception at the time of checking no common element exists.

在检查不存在公共元素时, disjoint()方法可能会引发异常。

NullPointerException: This exception may throw when the given parameter is null exists.

NullPointerException :当给定参数为null时,可能引发此异常。

Syntax:

句法:

public static boolean disjoint(Collection cl1, Collection cl2);


Parameter(s):

参数:

Collection cl1, Collection cl2 – represent the different Collection objects.

集合cl1,集合cl2 –表示不同的集合对象。

Return value:

返回值:

The return type of this method is boolean, it returns true when no common element exists in Collection object otherwise it returns false.

此方法的返回类型为boolean ,当Collection对象中不存在公共元素时返回true,否则返回false。

举例:

List<String> idList1 = new ArrayList();
List<String> idList2= new ArrayList();
idList1.add("id1");
idList2.add("id2");
if(Collections.disjoint(idList1,idList2))
{
    result.error500("不等!");
}


qrcode