tag:blogger.com,1999:blog-8712770457197348465.post1220490371904661604..comments2024-03-18T22:43:46.707-07:00Comments on Javarevisited: How to parse String to Enum in Java | Convert Enum to String with Examplejavin paulhttp://www.blogger.com/profile/15028902221295732276noreply@blogger.comBlogger4125tag:blogger.com,1999:blog-8712770457197348465.post-72506223886575457222015-12-12T05:41:05.699-08:002015-12-12T05:41:05.699-08:00If you try to convert a String to enum for a Strin...If you try to convert a String to enum for a String that does not match exactly to the name of a value of your enum it will throw an exception. Wrapping your conversion with a try catch can be tedious, especially when it happens frequently in your application. If your enum has only a few values, iterating through them for a match can be faster than using a try catch and returns a null for Anonymoushttps://www.blogger.com/profile/10939091044212106220noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-16132621836696828052013-06-25T12:06:39.406-07:002013-06-25T12:06:39.406-07:00I don't like the above example. In my opinion ...I don't like the above example. In my opinion making every enum value an anonymous class makes it too complex. Hardcodec strings are not good too and, finally, enum converted to string and from string back to enum won't be the same. I've had in my job a situation when I had to make an enum from strings incoming from the remote server an then I started to use a pattern like this:<br />Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-84402052878598284212012-03-11T20:51:47.278-07:002012-03-11T20:51:47.278-07:00hi, by default when we convert Enum to String its ...hi, by default when we convert Enum to String its return face value of Enum i.e. how it has written, is there any way we can get customized String values from Enum, I am thinking of method like toString, does Enum provides toString() in Java ?kumudnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-12371010888052559162011-12-27T05:46:28.988-08:002011-12-27T05:46:28.988-08:00Thanks for you comment Kiran, Good to know that yo...Thanks for you comment Kiran, Good to know that you like this Enum to String conversion tutorial.Javin @ Convert Date to String javahttp://javarevisited.blogspot.com/2011/09/convert-date-to-string-simpledateformat.htmlnoreply@blogger.com