Java Relational Operators

Java relational operators are used to compare two values and return a boolean value true or false. The following are the relational operators in Java:

  1. Greater than: >
    The greater than operator checks whether the left operand is greater than the right operand.
refer‮igi:ot ‬ftidea.com
int a = 10;
int b = 5;
boolean result = a > b; // result is true
  1. Less than: <
    The less than operator checks whether the left operand is less than the right operand.
int a = 10;
int b = 5;
boolean result = a < b; // result is false
  1. Greater than or equal to: >=
    The greater than or equal to operator checks whether the left operand is greater than or equal to the right operand.
int a = 10;
int b = 5;
boolean result = a >= b; // result is true
  1. Less than or equal to: <=
    The less than or equal to operator checks whether the left operand is less than or equal to the right operand.
int a = 10;
int b = 5;
boolean result = a <= b; // result is false
  1. Equal to: ==
    The equal to operator checks whether the left operand is equal to the right operand.
int a = 10;
int b = 10;
boolean result = a == b; // result is true
  1. Not equal to: !=
    The not equal to operator checks whether the left operand is not equal to the right operand.
int a = 10;
int b = 5;
boolean result = a != b; // result is true