Search code examples
javacomparisonoperators

Does Java support chained inequality comparisons such as (5 < i < 10)?


Is there any operator or trick for such operation? Or is it necessary to use this:

if (5 < i && i < 10) {
    // ...
}

Solution

  • There is no such thing in Java (unless you work with booleans).

    The 5<iresults in a boolean on the left side on <10 which the compiler dislikes.