Skip to content

Most visited

Recently visited

navigation
Added in API level 1

EnumSet

public abstract class EnumSet
extends AbstractSet<E extends Enum<E>> implements Cloneable, Serializable

java.lang.Object
   ↳ java.util.AbstractCollection<E extends java.lang.Enum<E>>
     ↳ java.util.AbstractSet<E extends java.lang.Enum<E>>
       ↳ java.util.EnumSet<E extends java.lang.Enum<E>>


An EnumSet is a specialized Set to be used with enums as keys.

Summary

Public methods

static <E extends Enum<E>> EnumSet<E> allOf(Class<E> elementType)

Creates an enum set filled with all the enum elements of the specified elementType.

EnumSet<E> clone()

Creates a new enum set with the same elements as those contained in this enum set.

static <E extends Enum<E>> EnumSet<E> complementOf(EnumSet<E> s)

Creates an enum set.

static <E extends Enum<E>> EnumSet<E> copyOf(EnumSet<E> s)

Creates an enum set.

static <E extends Enum<E>> EnumSet<E> copyOf(Collection<E> c)

Creates an enum set.

static <E extends Enum<E>> EnumSet<E> noneOf(Class<E> elementType)

Creates an empty enum set.

static <E extends Enum<E>> EnumSet<E> of(E e1, E e2, E e3, E e4)

Creates a new enum set, containing only the specified elements.

static <E extends Enum<E>> EnumSet<E> of(E start, E... others)

Creates a new enum set, containing only the specified elements.

static <E extends Enum<E>> EnumSet<E> of(E e)

Creates a new enum set, containing only the specified element.

static <E extends Enum<E>> EnumSet<E> of(E e1, E e2)

Creates a new enum set, containing only the specified elements.

static <E extends Enum<E>> EnumSet<E> of(E e1, E e2, E e3, E e4, E e5)

Creates a new enum set, containing only the specified elements.

static <E extends Enum<E>> EnumSet<E> of(E e1, E e2, E e3)

Creates a new enum set, containing only the specified elements.

static <E extends Enum<E>> EnumSet<E> range(E start, E end)

Creates an enum set containing all the elements within the range defined by start and end (inclusive).

Inherited methods

From class java.util.AbstractSet
From class java.util.AbstractCollection
From class java.lang.Object
From interface java.util.Set
From interface java.util.Collection
From interface java.lang.Iterable

Public methods

allOf

Added in API level 1
EnumSet<E> allOf (Class<E> elementType)

Creates an enum set filled with all the enum elements of the specified elementType.

Parameters
elementType Class: the class object for the elements contained.
Returns
EnumSet<E> an enum set with elements solely from the specified element type.
Throws
ClassCastException if the specified element type is not and enum type.

clone

Added in API level 1
EnumSet<E> clone ()

Creates a new enum set with the same elements as those contained in this enum set.

Returns
EnumSet<E> a new enum set with the same elements as those contained in this enum set.

complementOf

Added in API level 1
EnumSet<E> complementOf (EnumSet<E> s)

Creates an enum set. All the contained elements complement those from the specified enum set.

Parameters
s EnumSet: the specified enum set.
Returns
EnumSet<E> an enum set with all the elements complementary to those from the specified enum set.
Throws
NullPointerException if s is null.

copyOf

Added in API level 1
EnumSet<E> copyOf (EnumSet<E> s)

Creates an enum set. All the contained elements are of type Class<E>, and the contained elements are the same as those contained in s.

Parameters
s EnumSet: the enum set from which to copy.
Returns
EnumSet<E> an enum set with all the elements from the specified enum set.
Throws
ClassCastException if the specified element type is not and enum type.

copyOf

Added in API level 1
EnumSet<E> copyOf (Collection<E> c)

Creates an enum set. The contained elements are the same as those contained in collection c. If c is an enum set, invoking this method is the same as invoking copyOf(EnumSet).

Parameters
c Collection: the collection from which to copy. if it is not an enum set, it must not be empty.
Returns
EnumSet<E> an enum set with all the elements from the specified collection.
Throws
IllegalArgumentException if c is not an enum set and contains no elements at all.
NullPointerException if c is null.

noneOf

Added in API level 1
EnumSet<E> noneOf (Class<E> elementType)

Creates an empty enum set. The permitted elements are of type Class<E>.

Parameters
elementType Class: the class object for the elements contained.
Returns
EnumSet<E> an empty enum set, with permitted elements of type elementType.
Throws
ClassCastException if the specified element type is not and enum type.

of

Added in API level 1
EnumSet<E> of (E e1, 
                E e2, 
                E e3, 
                E e4)

Creates a new enum set, containing only the specified elements. There are six overloadings of the method. They accept from one to five elements respectively. The sixth one receives an arbitrary number of elements, and runs slower than those that only receive a fixed number of elements.

Parameters
e1 E: the initially contained element.
e2 E: another initially contained element.
e3 E: another initially contained element.
e4 E: another initially contained element.
Returns
EnumSet<E> an enum set containing the specified elements.
Throws
NullPointerException if any of the specified elements is null.

of

Added in API level 1
EnumSet<E> of (E start, 
                E... others)

Creates a new enum set, containing only the specified elements. It can receive an arbitrary number of elements, and runs slower than those only receiving a fixed number of elements.

Parameters
start E: the first initially contained element.
others E: the other initially contained elements.
Returns
EnumSet<E> an enum set containing the specified elements.
Throws
NullPointerException if any of the specified elements is null.

of

Added in API level 1
EnumSet<E> of (E e)

Creates a new enum set, containing only the specified element. There are six overloadings of the method. They accept from one to five elements respectively. The sixth one receives an arbitrary number of elements, and runs slower than those that only receive a fixed number of elements.

Parameters
e E: the element to be initially contained.
Returns
EnumSet<E> an enum set containing the specified element.
Throws
NullPointerException if e is null.

of

Added in API level 1
EnumSet<E> of (E e1, 
                E e2)

Creates a new enum set, containing only the specified elements. There are six overloadings of the method. They accept from one to five elements respectively. The sixth one receives an arbitrary number of elements, and runs slower than those that only receive a fixed number of elements.

Parameters
e1 E: the initially contained element.
e2 E: another initially contained element.
Returns
EnumSet<E> an enum set containing the specified elements.
Throws
NullPointerException if any of the specified elements is null.

of

Added in API level 1
EnumSet<E> of (E e1, 
                E e2, 
                E e3, 
                E e4, 
                E e5)

Creates a new enum set, containing only the specified elements. There are six overloadings of the method. They accept from one to five elements respectively. The sixth one receives an arbitrary number of elements, and runs slower than those that only receive a fixed number of elements.

Parameters
e1 E: the initially contained element.
e2 E: another initially contained element.
e3 E: another initially contained element.
e4 E: another initially contained element.
e5 E: another initially contained element.
Returns
EnumSet<E> an enum set containing the specified elements.
Throws
NullPointerException if any of the specified elements is null.

of

Added in API level 1
EnumSet<E> of (E e1, 
                E e2, 
                E e3)

Creates a new enum set, containing only the specified elements. There are six overloadings of the method. They accept from one to five elements respectively. The sixth one receives an arbitrary number of elements, and runs slower than those that only receive a fixed number of elements.

Parameters
e1 E: the initially contained element.
e2 E: another initially contained element.
e3 E: another initially contained element.
Returns
EnumSet<E> an enum set containing the specified elements.
Throws
NullPointerException if any of the specified elements is null.

range

Added in API level 1
EnumSet<E> range (E start, 
                E end)

Creates an enum set containing all the elements within the range defined by start and end (inclusive). All the elements must be in order.

Parameters
start E: the element used to define the beginning of the range.
end E: the element used to define the end of the range.
Returns
EnumSet<E> an enum set with elements in the range from start to end.
Throws
NullPointerException if any one of start or end is null.
IllegalArgumentException if start is behind end.
This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.