File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Get Enum By Ordinal
Joined: Aug 09, 2007
May 01, 2008 09:58:00
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?
Joined: Jan 30, 2000
May 01, 2008 10:18:00
Yes. Condition.values() returns an array of all values in order by ordinal. So Condition.values() returns the Condition for ordinal 0.
"I'm not back." - Bill Harding,
It is sorta covered in the
JavaRanch Style Guide
subject: Get Enum By Ordinal
Ordinal Value of ENUM and JPA
Assigning values to instance fields
Start java enum ordinal at 1 instead of 0
Java "enum" : can you use non-consecutive ordinal numbers ?
"casting" an int to an enum type
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2015