Use EnumSet to store enum type data : EnumSet « Collections Data Structure « Java






Use EnumSet to store enum type data


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

public class SizeSet {
    
    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;

}

 








Related examples in the same category