Java Utililty Methods EnumSet Create

List of utility methods to do EnumSet Create

Description

The list of methods to do EnumSet Create are organized into topic(s).

Method

EnumSetof(E e1, E... e)
of
return EnumSet.of(e1, e);
EnumSetof(E[] c)
of
if (c.length == 0) {
    throw new IllegalArgumentException("Collection is empty");
EnumSet<E> result = EnumSet.of(c[0]);
if (c.length > 1) {
    for (int i = 1; i < c.length; i++) {
        result.add(c[i]);
return result;
EnumSetparseEnum(final Class klass, final String input)
parse Enum
return parseEnum(klass, input, "\\s*,\\s*");
EnumSettoEnumSet(Class classValue, Collection stringValues)
to Enum Set
EnumSet<E> result = EnumSet.noneOf(classValue);
for (String s : stringValues) {
    result.add(Enum.valueOf(classValue, s));
return result;
EnumSettoEnumSet(Class enumClass, long vector)
to Enum Set
EnumSet<E> set = EnumSet.noneOf(enumClass);
long mask = 1;
for (E e : enumClass.getEnumConstants()) {
    if ((mask & vector) == mask) {
        set.add(e);
    mask <<= 1;
return set;
EnumSettoEnumSet(Class clazz, T... ts)
Turns an array of enumeration values into an enum set
if (ts == null)
    return null;
EnumSet<T> res = EnumSet.noneOf(clazz);
for (T t : ts) {
    res.add(t);
return res;