java 集合枚举_java枚举转集合_枚举集

java枚举转集合

In Java, EnumSet extends the AbstractSet and is implemented in the Set interface. This class is the member of the Java Collection Framework and also it can not be synchronized. EnumDet is faster than HashSet.

在Java中,EnumSet扩展了AbstractSet并在Set接口中实现。 此类是Java Collection Framework的成员,并且无法同步。 EnumDet比HashSet快。

Syntax:

句法:

public abstract class EnumSet>

下面是EnumSet类的方法 (Below are the methods of EnumSet Class)

S.no.

Method

Description

1

EnumSet of(E e1)

It is used to create an Enum set using specified elements.

2

EnumSetcomplementOf(EnumSet s)

It is used to create an Enum set using specified elements which are unique.

3

EnumSetallOf(Class elementType)

It is used to create an Enum set using all the elements of the class.

4

EnumSet range(E from, E to)

It is used to get the Enum elements of the given range.

5

EnumSetcopyof()

It is used to copy the elements from the collection in a new enum set.

序号

方法

描述

1个

(E e1)的EnumSet

它用于使用指定的元素创建一个Enum集。

2

EnumSetcomplementOf(EnumSet s)

它用于使用唯一的指定元素创建一个Enum集。

3

EnumSetallOf(Class elementType)

它用于使用该类的所有元素创建一个Enum集。

4

EnumSet范围(E从,E到)

它用于获取给定范围的Enum元素。

5

EnumSetcopyof()

它用于在新的枚举集中复制集合中的元素。

Example:

例:

import java.util.EnumSet;

enum Demo1

{

RED, BLACK, BLUE, PINK, WHITE

};

public class EnumDemo1

{

public static void main(String[] args)

{

EnumSet1a1, a2, a3, a4;

a1 = EnumSet1.of(Demo1.RED, Demo1.BLACK, Demo1.BLUE, Demo1.PINK, Demo1.WHITE);

a2 = EnumSet1.complementOf(a1);

a3 = EnumSet1.allOf(Demo1.class);

a4 = EnumSet1.range(Demo1.RED, Demo1.PINK);

System.out.println("a 1: " + a1);

System.out.println("a 2: " + a2);

System.out.println("a 3: " + a3);

System.out.println("a 4: " + a4);

}

}

f4246b5a07e9e2e818ce236d3b3cf4de.png

翻译自: https://www.studytonight.com/java/enum-set.php

java枚举转集合

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值