I think you want something like this,
public static enum CardSuit {
SPADE(0), HEART(1), DIAMOND(2), CLUB(3);
int value;
CardSuit(int v) {
this.value = v;
}
public String toString() {
return this.name();
}
}
public static void main(String[] args) {
CardSuit s = CardSuit.values()[0];
System.out.println(s);
}
Output is
SPADE
Edit
If you wanted to search by the assigned value, you could do it with something like this -
public static enum CardSuit {
SPADE(0), HEART(1), DIAMOND(4), CLUB(2);
int value;
CardSuit(int v) {
this.value = v;
}
public String toString() {
return this.name();
}
public static CardSuit byValue(int value) {
for (CardSuit cs : CardSuit.values()) {
if (cs.value == value) {
return cs;
}
}
return null;
}
}
public static void main(String[] args) {
CardSuit s = CardSuit.byValue(2);
System.out.println(s);
}
Output is
CLUB