• Post Reply Bookmark Topic Watch Topic
  • New Topic

Putting an enum in hashmap value  RSS feed

 
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have data of the type say:
EmployeeID ClassEnum

Now i want to store the value in a HashMap<String, ClassEnum> . But since it gets parsed as String when i parse the file, how can i say that it needs to be typecasted to ClassEnum.

Please advise

Thanks,
 
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't really understand your question. Do you store the enum value as a String? In that case you can use EnumClass.valueOf(name).
 
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use name() to convert the enum instance to a String, and as Wouter suggested the enum class's own static valueOf method for converting the String back into an enum instance. Those two are working in opposite ways.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!