Reputation: 1
I have a pair of related enums in Java.
Enum Alphabet
{
A, B, C;
}
Enum Phonetic
{
Alpha (Alphabet.A, Amber)
Bravo (Alphabet.B, Beta)
Charlie (Alphabet.C, Cookie)
}
How do I convert the Alphabet.A values in enum phonetic into a string?
Upvotes: 0
Views: 46
Reputation: 10250
If you have two sets of enums that have equivalent values stored in the same order, then you can use the ordinal value from one to look up the equivalent value from the other.
int ord=Alphabet.A.ordinal();
Phonetic equiv=Phonetic.values()[ord];
System.out.println(equiv);
Upvotes: 1