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

EnumSet Of 

The following example shows how to create an enum set containing the specified element(s). EnumSet provides the following APIs,

public static <E extends Enum<E>> EnumSet<E> of(E paramE1)
public static <E extends Enum<E>> EnumSet<E> of(E paramE1, E paramE2)
public static <E extends Enum<E>> EnumSet<E> of(E paramE1, E paramE2, E paramE3)
 - Returns enum set containing the specified element(s). 


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

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

public class EnumSetOfTest {

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

    EnumSet<Fruit> enumSet = EnumSet.of(Fruit.APPLE, Fruit.ORANGE, Fruit.BANANA);
    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]
APPLE-->0
ORANGE-->1
BANANA-->2


                    Print

   



Books Recommendation

 
 
bl  br