java 方法 示例_带有示例的Java EnumSetSupplementOf()方法

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 方法 示例

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值