Apache's commons-langCommons Lang library has a static function org.apache.commons.lang3.EnumUtils.getEnumorg.apache.commons.lang3.EnumUtils.getEnum which will map a String to your EnumEnum type. Same answer essentially as Geoffrey Zheng's, but there isn't any need to roll your own when it's out there in the wild already.
Used a more direct cross reference (as user names can change at any time). More affirmative answer (this is not a forum - see e.g. <http://meta.stackexchange.com/a/92115>. It is a think tank (see <http://meta.stackoverflow.com/a/325681>).
Peter Mortensen
- 31.4k
- 22
- 110
- 134