To convert a string to enum in Java you can use the following snippet.

Considering the following enum.

Sample Java

public enum Testenum {
  One,Two,Three,Four
}

you can cast an string to enum like this:

Sample Java

Testenum.valueOf("Two");

6 thought on “How to convert a string to enum in Java”

Leave a Reply