Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / Java

Less-than-or-equal operator (<=)

The <= operator compares numeric values inclusively. It returns boolean; a comparison involving NaN returns false.

Version: Java SE 21; repository runtime, production runtime not attested

Syntax

left <= right

left <= right returns true when the left value is less than or equal to the right; otherwise, false. The result has type boolean.

Operands undergo binary numeric promotion. This includes char and unboxing numeric wrapper types such as Integer; unboxing null throws NullPointerException. The operator does not compare boolean values or String objects.

If either operand is NaN, the result is false. The zeros -0.0 and 0.0 compare equal.

Do not write a range as a <= b <= c: it is a compilation error. Use a <= b && b <= c.

Examples

public class Main {
    public static void main(String[] args) {
        int count = 3;
        int limit = 3;
        System.out.println(count <= limit);
        System.out.println(4 <= limit);
        System.out.println(Double.NaN <= limit);
        System.out.println(-0.0 <= 0.0);
    }
}

Result

true
false
false
true

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources