Java - Less Than Operator <

What is Less Than Operator

The less than operator < has the following form

operand1 < operand2 
  

The less than operator returns true if operand1 is less than operand2. Otherwise, it returns false.

The operator can be used only with primitive numeric data types.

If either operand is NaN (float or double), the less than operator returns false.

Example

The following code shows how to use the Less Than Operator.

int i = 10; 
int j = 15; 
double d1 = Double.NaN; 
boolean b; 
b = (i < j);  // Assigns true to b 
b = (j < i);  // Assigns false to b 
b = (d1 < Double.NaN);  // Assigns false to b 

Demo

public class Main {
  public static void main(String[] args) {
    int i = 10; /*from  w  ww.  jav a  2s.co m*/
    int j = 15; 
    double d1 = Double.NaN; 
    boolean b; 
    b = (i < j);  // Assigns true to b
    System.out.println(b);
    b = (j < i);  // Assigns false to b 
    System.out.println(b);
    
    b = (d1 < Double.NaN);  // Assigns false to b 
    System.out.println(b);
  }
}

Result

< cannot be used with boolean operands

b = (true < false); // A compile-time error.