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.

1 Answer 1


I have found the following solution

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .