Java by API/java.util/EnumMap
Версия от 17:43, 31 мая 2010; (обсуждение)
EnumMap: get(Object key)
import java.util.EnumMap;
public class Main {
public static void main(String[] args) {
EnumMap<Size, String> sizeMap = new EnumMap<Size, String>(Size.class);
sizeMap.put(Size.S, "S");
sizeMap.put(Size.M, "M");
sizeMap.put(Size.L, "L");
sizeMap.put(Size.XL, "XL");
sizeMap.put(Size.XXL, "XXL");
sizeMap.put(Size.XXXL, "XXXL");
for (Size size : Size.values()) {
System.out.println(size + ":" + sizeMap.get(size));
}
}
}
enum Size {
S, M, L, XL, XXL, XXXL;
}
EnumMap: put(T key, R value)
import java.util.EnumMap;
public class Main {
public static void main(String[] args) {
EnumMap<Size, String> sizeMap = new EnumMap<Size, String>(Size.class);
sizeMap.put(Size.S, "S");
sizeMap.put(Size.M, "M");
sizeMap.put(Size.L, "L");
sizeMap.put(Size.XL, "XL");
sizeMap.put(Size.XXL, "XXL");
sizeMap.put(Size.XXXL, "XXXL");
for (Size size : Size.values()) {
System.out.println(size + ":" + sizeMap.get(size));
}
}
}
enum Size {
S, M, L, XL, XXL, XXXL;
}
new EnumMap(Class keyType)
import java.util.EnumMap;
public class Main {
public static void main(String[] args) {
EnumMap<Size, String> sizeMap = new EnumMap<Size, String>(Size.class);
sizeMap.put(Size.S, "S");
sizeMap.put(Size.M, "M");
sizeMap.put(Size.L, "L");
sizeMap.put(Size.XL, "XL");
sizeMap.put(Size.XXL, "XXL");
sizeMap.put(Size.XXXL, "XXXL");
for (Size size : Size.values()) {
System.out.println(size + ":" + sizeMap.get(size));
}
}
}
enum Size {
S, M, L, XL, XXL, XXXL;
}