tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 
 Java > Collection > EnumSet > EnumSet AllOf

EnumSet AllOf 

The following example shows how to create an enum set containing all of the elements in the specified element type. EnumSet provides the following APIs,

public static <E extends Enum<E>> EnumSet<E> allOf(Class<E> paramClass);
 - Returns enum set containing all of the elements in the specified element type. 


File Name  :  
com/bethecoder/tutorials/utils/enums/EnumSetAllOfTest.java 
Author  :  Sudhakar KV
Email  :  kvenkatasudhakar@gmail.com
   
package com.bethecoder.tutorials.utils.enums;

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

public class EnumSetAllOfTest {

  /**
   @param args
   */
  public static void main(String[] args) {

    EnumSet<Fruit> enumSet = EnumSet.allOf(Fruit.class);
    System.out.println(enumSet);
    
    Iterator<Fruit> it = enumSet.iterator();
    Fruit fruit = null;
    
    while (it.hasNext()) {
      fruit = it.next();
      System.out.println(fruit + "-->" + fruit.ordinal());
    }
    
  }

}
   


File Name  :  
com/bethecoder/tutorials/utils/enums/Fruit.java 
   
package com.bethecoder.tutorials.utils.enums;

public enum Fruit {
  APPLE,
  ORANGE,
  BANANA,
  CHERRY,
  MANGO
}
   

It gives the following output,
[APPLE, ORANGE, BANANA, CHERRY, MANGO]
APPLE-->0
ORANGE-->1
BANANA-->2
CHERRY-->3
MANGO-->4


                    Print

   



Books Recommendation

 
 
bl  br