Java EnumMap create

Description

Java EnumMap create



import java.util.EnumMap;
import java.util.Map;
enum Letter{//from w ww .  j  a  v  a2 s . co m
  S, M, L, X, A, B;
}

public class Main {

  public static void main(String[] args) {
    Map<Letter, String> sizeMap = new EnumMap<Letter, String>(Letter.class);
    sizeMap.put(Letter.S, "S");
    sizeMap.put(Letter.M, "M");
    sizeMap.put(Letter.L, "L");
    sizeMap.put(Letter.X, "X");
    sizeMap.put(Letter.A, "A");
    sizeMap.put(Letter.B, "B");
    
    for (Letter letter : Letter.values()) {
      System.out.println(letter + ":" + sizeMap.get(letter));
    }
  }
}



PreviousNext

Related