Relational Operators
This class of operators contain those operators which are used to perform relational operation on the operands. It goes like this:
Operator Symbol | Operator Name | Operator Description |
---|---|---|
> | Greater than | Check which operand is bigger and give result as boolean expression. |
< | Less than | Check which operand is smaller and give result as boolean expression. |
>= | Greater than or equal to | Check which operand is greater or equal to each other and give result as boolean expression. |
<= | less than equal to | Check which operand is less than or equal to each other and give result as boolean expression. |
== | Equal to | Check whether the operand are equal to each other or not and give result as boolean expression. |
!= | Not Equal to | Check whether the operand are not equal to each other or not and give result as boolean expression. |
Example showing the use of Relational Operators:
// Dart Program Demonstrating use
// Of all Relational Operators
void main()
{
int a = 2;
int b = 3;
// Greater between a and b
var c = a > b;
print("a is greater than b (a > b) : $c");
// Smaller between a and b
var d = a < b;
print("a is smaller than b (a < b) : $d");
// Greater than or equal to between a and b
var e = a >= b;
print("a is greater than b (a >= b) : $e");
// Less than or equal to between a and b
var f = a <= b;
print("a is smaller than b (a <= b) : $f");
// Equality between a and b
var g = b == a;
print("a and b are equal (b == a) : $g");
// Unequality between a and b
var h = b != a;
print("a and b are not equal (b != a) : $h");
}
Output:
a is greater than b (a > b) : false
a is smaller than b (a < b) : true
a is greater than b (a >= b) : false
a is smaller than b (a <= b) : true
a and b are equal (b == a) : false
a and b are not equal (b != a) : true
Note: == operator can’t be used to check if the object is same. So, to check if the object are same we use identical() function.
Operators in Dart
The operators are special symbols that are used to carry out certain operations on the operands. The Dart has numerous built-in operators which can be used to carry out different functions, for example, ‘+’ is used to add two operands. Operators are meant to carry operations on one or two operands.