top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to convert String into Enum in Java

+2 votes
294 views
How to convert String into Enum in Java
posted Jan 7, 2015 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

Use the valueOf method on the ENUM class.

DemoType demoType =   DemoType.valueOf("DAILY")

It'll throw an IllegalArgumentException should the string argument provided be invalid. Using your example

DemoType demoType =  DemoType.valueOf("HOURLY");

The line above will throw an IllegalArgumentException because HOURLY is not part of your DemoType

answer Jan 12, 2015 by Manikandan J
...