Skip to main content
The < (less than) operator is a binary relational operator that compares the values of two numeric operands. It evaluates to the boolean value true if the left-hand operand is strictly lesser in mathematical value than the right-hand operand, and false otherwise.

Operand Compatibility

The < operator strictly requires operands that can be resolved to numeric types.
  • Supported Primitives: byte, short, char, int, long, float, and double.
  • Unsupported Types: boolean, String, and all object references (with the exception of numeric wrapper classes).

Binary Numeric Promotion

Before performing the comparison, Java applies binary numeric promotion to the operands according to the Java Language Specification. This promotion occurs for all numeric comparisons based on the following strict hierarchy:
  1. If either operand is of type double, the other is promoted to double.
  2. Otherwise, if either operand is of type float, the other is promoted to float.
  3. Otherwise, if either operand is of type long, the other is promoted to long.
  4. Otherwise, both operands are promoted to int.
This means that operands of types smaller than int (byte, short, and char) are always widened to int prior to comparison, even if both operands are of the exact same type or if the broadest type between the two is smaller than int.

Auto-Unboxing

If either operand is a numeric wrapper class (e.g., Integer, Double, Character), Java automatically unboxes the object into its corresponding primitive type before applying binary numeric promotion and evaluating the relational expression.
Note: If the wrapper reference is null, the unboxing attempt will throw a NullPointerException.

Floating-Point Specifics

When evaluating float or double operands, the < operator adheres to IEEE 754 standards for floating-point arithmetic:
  • NaN (Not a Number): If either operand is NaN, the < operator always evaluates to false.
  • Infinity: Negative infinity (-Infinity) is considered strictly less than any finite value and positive infinity (+Infinity).
  • Signed Zeros: Positive zero (0.0) and negative zero (-0.0) are considered equal. Therefore, -0.0 < 0.0 evaluates to false.

Character Comparison

When applied to char operands, the < operator compares their 16-bit Unicode (UTF-16) integer values.
Tired of Poor Java Skills? Fix That With Deep Grasping!Learn More