CKTIS / Java
Less-than operator (<)
The < operator checks whether its left operand is strictly less than its right operand and returns boolean. Equal values produce false. Floating-point comparisons require care with NaN and signed zeros.
Version: Java SE 21; repository runtime, production runtime not attested
Syntax
left < rightThe expression left < right returns true when the left numeric value is strictly less than the right; otherwise it returns false. The result has type boolean. Unlike <=, the < operator excludes equality.
Operands must be numeric or unboxable to numeric types; this includes char. Java applies binary numeric promotion, which can lose precision. Unboxing null throws NullPointerException. The operator does not compare boolean values or String objects.
For float and double, a comparison with NaN on either side returns false. Positive and negative zero are equal, so -0.0 < 0.0 returns false.
Do not write a < b < c: it is a compile-time error because a < b has type boolean. Write a < b && b < c instead.
Examples
public class LessThanDemo {
public static void main(String[] args) {
int count = 3;
int limit = 5;
System.out.println(count < limit);
System.out.println(limit < limit);
System.out.println(Double.NaN < limit);
System.out.println(-0.0 < 0.0);
}
}Result
true false false false
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.