We have valueOf() method which can be used to convert a string to enum.
package convertstringtoenum; enum EventReturnStatus { SUCCESS, FAILURE, HOLD; } public class StringToEnumExample { public static void main(String[] args) { String s1 = "HOLD"; EventReturnStatus returnStatus = EventReturnStatus.valueOf(s1); System.out.println(returnStatus); } }
Output is –
HOLD