Get enum from integer value (ordinal)
A simple way to get the enum indicated by its ordinal value.
Copy this code and paste it in your HTML
public class EnumTester {
enum Color { RED, GREEN, BLUE
};
public static void main
(String[] args
) {
int selection = 1;
Color selectedColor
= Color.
values()[ selection
];
System.
out.
println("Selected color ="+selectedColor
); }
}
Report this snippet
Comments
Subscribe to comments