, , : int.
, , Java Map. , Map<type, Integer> ( EnumMap, Enum).
Map<Color, Integer> map = new EnumMap<Color, Integer>(Color.class);
map.put(Color.BLUE, 3);
, , ordinal() ( int, , 0):
int[] ints = new int[Color.values().length];
ints[Color.BLUE.ordinal()] = 3;
( , , , - BLUE --> 2 BLUE --> 3), :
enum Color {
GREEN, BLUE, BLACK, GRAY;
private int value;
}
:
Color.BLUE.setValue(8);
:
for (Color c : Color.values()) {
System.out.println("There are " + c.getValue() + " occurences of " + c);
}