public
enum
Fruit {
APPLE, BANANA, ORANGE;
public
static
Fruit getValue(String str) {
if
(APPLE.name().equalsIgnoreCase(str)) {
return
APPLE;
}
else
if
(BANANA.name().equalsIgnoreCase(str)) {
return
BANANA;
}
else
if
(ORANGE.name().equalsIgnoreCase(str)){
return
ORANGE;
}
return
null
;
}
}
Read full article from Java – Convert string to enum | CoralCode
No comments:
Post a Comment