When I declare Enum class public Enum X{A,B,C} and I have Enum variable X y and I need to increment that value, in other languages I could just write y++ to increment it, that is, to change A to B, B to C, C to A.


I have found the following solution

public static X inc(X y) {
    return X.values()[Math.mod(y.ordinal()+1, X.values().size())];

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.