java 方法 示例
EnumSet类complementOf()方法 (EnumSet Class complementOf() method)
complementOf() method is available in java.util package.
clipartOf()方法在java.util包中可用。
complementOf() method is used to contain all the elements of this EnumSet that are complement in the given EnumSet.
clipartOf()方法用于包含此EnumSet的所有元素,这些元素在给定的EnumSet中是互补的。
complementOf() method is a static method, 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.
complementOf()方法是一个静态方法,可以使用类名进行访问,如果尝试使用类对象访问该方法,则不会出错。
complementOf() method may throw an exception at the time of returning complement EnumSet.
在返回补码EnumSet时, complementOf()方法可能会引发异常。
NullPointerException: This exception may throw when the given parameter is null exists.
NullPointerException :当给定参数为null时,可能引发此异常。
Syntax:
句法:
public static EnumSet complementOf(EnumSet es);
Parameter(s):
参数:
EnumSet es – represents the another enum set from whose complement to assign this enum set.
EnumSet es –表示另一个枚举集,从该枚举的补码中分配该枚举集。
Return value:
返回值:
The return type of this method is EnumSet, it returns complement enum set of the given enum set.
此方法的返回类型为EnumSet ,它返回给定枚举集的互补枚举集。
Example:
例:
// Java program is to demonstrate the example of
// complementOf(EnumSet es) method of EnumSet
import java.util.*;
public class ComplementOfEnumSet {
// Initialize a enum variable
// with some constants
public enum Colors {
RED,
BLUE,
GREEN,
PURPLE,
YELLOW
};
public static void main(String[] args) {
// Here , we are creating two EnumSet
// First EnumSet is intiatize with some
// values and Second EnumSet is empty
EnumSet < Colors > es = EnumSet.of(Colors.PURPLE);
EnumSet < Colors > complement_es = null;
// Display EnumSet
System.out.println("EnumSet (es): " + es);
// By using complementOf() method is to
// contain all of the elements that does
// not exists in the given EnumSet es
complement_es = EnumSet.complementOf(es);
// Display EnumSet
System.out.println("EnumSet.complementOf(es): " + complement_es);
}
}
Output
输出量
EnumSet (es): [PURPLE]
EnumSet.complementOf(es): [RED, BLUE, GREEN, YELLOW]
翻译自: https://www.includehelp.com/java/enumset-complementof-method-with-example.aspx
java 方法 示例