Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Get Enum By Ordinal

 
Jason Ferguson
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a Enum named condition.

The ordinal value for Condition.A is 0. The ordinal() method will return the ordinal value of 0.

However, if I have the value of 0, is there a way I can get Condition.A from it without a switch statement?
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. Condition.values() returns an array of all values in order by ordinal. So Condition.values()[0] returns the Condition for ordinal 0.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic