Close

Java Collections - EnumSet.allOf() Examples

Java Collections Java Java API 


Class:

java.util.EnumSet

java.lang.Objectjava.lang.Objectjava.util.AbstractCollectionjava.util.AbstractCollectionjava.util.CollectionCollectionjava.util.AbstractSetjava.util.AbstractSetjava.util.SetSetjava.util.EnumSetjava.util.EnumSetjava.lang.CloneableCloneablejava.io.SerializableSerializableLogicBig

Method:

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

Creates an enum set containing all of the elements in the specified type.


Examples


package com.logicbig.example.enumset;

import java.time.DayOfWeek;
import java.util.EnumSet;

public class AllOfExample {

public static void main(String... args) {
EnumSet<DayOfWeek> set = EnumSet.allOf(DayOfWeek.class);
System.out.println(set);
//set is modifiable
set.remove(DayOfWeek.SUNDAY);
System.out.println("-- after modification --");
System.out.println(set);
}
}

Output

[MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY]
-- after modification --
[MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY]




See Also