Java | Relational Operators: Relational operators are using for compare the data.
List of Relational Operators:
.
Less Than: This operator checks if left value is less than right value or not. it is denoted by '<'.
Ex: 1 < 2.
Greater Than: This operator checks if left value is greater than right value or not. it is denoted by '>'.
Ex: 1 > 2.
Equal to: This operator is using to check if both values are equal or not. it is denoted by '=='.
Ex: 1 == 2.
Not Equal to: This operator is using to check if both values are not equal or not. it is denoted by '!='.
Ex: 1 != 2.
Less Than or Equal to: This operator checks if left value is less than or equal with right value or not. it is denoted by '<='.
Ex: 1 <= 2.
Greater Than or Equal to: This operator checks if left value is greater than or equal with right value or not. it is denoted by '>='.
Ex: 1 >= 2.
Here is the Code:
- import java.io.*;
- class Main {
- public static void main (String[] args) {
- // Less than
- System.out.println(1 < 2);
- // Greater than
- System.out.println(1 > 2);
- // Equal to
- System.out.println(1 == 2);
- // Not Equal to
- System.out.println(1 != 2);
- // Less than or Equal to
- System.out.println(1 <= 2);
- // Greater than or Equal to
- System.out.println(1 >= 2);
- // String Equals
- System.out.println("abc".equals("abc"));
- }
- }
Output:
true
false
false
true
true
false
true
Here is the Video: