dev ツ dev ツ - 1 year ago 83
Java Question

How to set enum on the basis of integer value in Java?

I have a


private enum Order {

I need set this enum on the basis of

  • 0 ==> DESC

  • 1 ==> ASC

public void setOrder(int order) {
// some code

Answer Source

As long as you have increasing value starting from 0 and the order in your enum is identical to the number ordering you can use the values() array:

Order desc = Order.values()[0];
Order asc = Order.values()[1];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download