Search code examples
javaoperatorsconditional-statements

alternative way to compare if three ints are equal


int a = 10;
int b = 10;
int c = 10;

I am trying to find out if there is alternate way to compare if three ints or anything are equal.

The way i am currently doing is

if( (a == b) && (a == c) && (b == c)){

}

I was wondering if there is an alternate and more concise way to do this.


Solution

  • Equality is transitive; you don't need the last comparison b == c. If a == b and a == c, then b == c.

    Try

    if ((a == b) && (a == c)){