EnumSet

                                             
    java.lang.Object                                        
     |                                       
     |--java.util.AbstractCollection                                    
         |                                   
         |--java.util.AbstractSet                                
             |                               
             |--java.util.EnumSet                            
                                             

A specialized Set implementation for use with enum types.

ReturnMethodSummary
static<E extends Enum<E>>EnumSet<E> allOf(Class<E> elementType) Creates an enum set containing all of the elements in the specified element type.
EnumSet<E>clone()Returns a copy of this set.
static<E extends Enum<E>>EnumSet<E> complementOf(EnumSet<E> s) 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.
static<E extends Enum<E>>EnumSet<E> copyOf(Collection<E> c) Creates an enum set initialized from the specified collection.
static<E extends Enum<E>>EnumSet<E> copyOf(EnumSet<E> s) Creates an enum set with the same element type as the specified enum set, initially containing the same elements (if any).
static<E extends Enum<E>>EnumSet<E> noneOf(Class<E> elementType) Creates an empty enum set with the specified element type.
static<E extends Enum<E>>EnumSet<E>of(E e)Creates an enum set initially containing the specified element.
static<E extends Enum<E>>EnumSet<E>of(E first, E... rest)Creates an enum set initially containing the specified elements.
static<E extends Enum<E>>EnumSet<E>of(E e1, E e2)Creates an enum set initially containing the specified elements.
static<E extends Enum<E>>EnumSet<E>of(E e1, E e2, E e3)Creates an enum set initially containing the specified elements.
static<E extends Enum<E>>EnumSet<E>of(E e1, E e2, E e3, E e4)Creates an enum set initially containing the specified elements.
static<E extends Enum<E>>EnumSet<E>of(E e1, E e2, E e3, E e4, E e5)Creates an enum set initially containing the specified elements.
static<E extends Enum<E>>EnumSet<E>range(E from, E to)Creates an enum set initially containing all of the elements in the range defined by the two specified endpoints.
Revised from Open JDK source code

import java.util.EnumSet;
import java.util.Iterator;

public class Main {
    
    public static void main(String[] args) {
        EnumSet largeSize = EnumSet.of(Size.XL,Size.XXL,Size.XXXL);
        for(Iterator it = largeSize.iterator();it.hasNext();){
            Size size = (Size)it.next();
            System.out.println(size);
        }
    }
}


enum Size {
  S, M, L, XL, XXL, XXXL;

}

The output:



XL
XXL
XXXL
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.