📜  Java.util.EnumSet类

📅  最后修改于: 2020-11-14 06:15:48             🧑  作者: Mango


介绍

java.util.EnumSet类是用于枚举类型的专用Set实现。以下是有关EnumSet的要点-

  • 枚举集中的所有元素都必须来自创建该枚举集时显式或隐式指定的单个枚举类型。

  • 枚举集在内部表示为位向量。

  • EnumSet不同步。如果多个线程同时访问一个枚举集,并且至少有一个线程修改了该枚举集,则应在外部进行同步。

类声明

以下是java.util.EnumSet类的声明-

public abstract class EnumSet>
   extends AbstractSet
   implements Cloneable, Serializable

类方法

Sr.No. Method & Description
1 static > EnumSet allOf(Class elementType)

This method creates an enum set containing all of the elements in the specified element type.

2 EnumSet clone()

This method returns a copy of this set.

3 static > EnumSet complementOf(EnumSet s)

This method creates an enum set with the same element type as the specified enum set, initially containing all the elements of this type that are not contained in the specified set.

4 static > EnumSet copyOf(Collection c)

This method creates an enum set initialized from the specified collection.

5 static > EnumSet copyOf(EnumSet s)

This method creates an enum set with the same element type as the specified enum set, initially containing the same elements (if any).

6 static > EnumSet noneOf(Class elementType)

This method creates an empty enum set with the specified element type.

7 static > EnumSet of(E e)

This method creates an enum set initially containing the specified element.

8 static > EnumSet of(E first, E… rest)

This method creates an enum set initially containing the specified elements.

9 static > EnumSet of(E e1, E e2)

This method creates an enum set initially containing the specified elements.

10 static > EnumSet of(E e1, E e2, E e3)

This method creates an enum set initially containing the specified elements.

11 static > EnumSet of(E e1, E e2, E e3, E e4)

This method creates an enum set initially containing the specified elements.

12 static > EnumSet of(E e1, E e2, E e3, E e4, E e5)

This method creates an enum set initially containing the specified elements.

13 static > EnumSet range(E from, E to)

This method creates an enum set initially containing all of the elements in the range defined by the two specified endpoints.

方法继承

此类从以下类继承方法-

  • java.util.AbstractSet
  • java.util.AbstractCollection
  • java.util.Object
  • java.util.Set