Dart Equality and Relational Operators
Dart provides the functionality of checking the relationship between the values or values within the variables.
These operators return the resultant value as Boolean, i.e., either ‘true’ or ‘false’.
Some important points to remember
- All these equality and relational operators are binary operators.
- The general structure of these equality and relational operator is similar to other binary operators :
Operand operator Operand
Operands refer to the values and Operator is the symbol that instructs the compiler about the function to be performed on the operands.
- In the case of strings, they are said to be equal only if these two strings contain the same character sequence.
List of Equality and Relational Operator
Let us consider the following table that contains the list of all the equality and relational operators in Dart.
For the following table, Consider A = 35, and B = 20
Operator |
Operator
Name |
Operator
Description |
Example |
> |
Greater
than |
This operator checks
which operand is bigger and gives the result as a Boolean expression. |
( A
> B ) will return False |
< |
Lesser
than |
This
operator checks which operand is smaller and gives the result as a Boolean
expression. |
( A
< B ) will return True |
>= |
Greater
than or equal to |
This operator checks
which operand is greater or equal to each other and gives the result as a
Boolean expression. |
( A
>= B ) will return False |
<= |
Lesser
than or equal to |
This
operator checks which operand is less than or equal to each other and gives the
result as a Boolean expression. |
( A
<= B ) will return True |
== |
Equality |
This operator checks
whether the operands are equal to each other or not and gives the result as a
Boolean expression. |
( A ==
B ) will return False |
!= |
Not
equal |
This
operator checks whether the operands are not equal to each other or not and gives
the result as a Boolean expression. |
( A !=
B ) will return True |
Consider the following code in the Dart language that explains the concept of Equality and Relational Operator
Program
void main( )
{
int a = 25, b = 30 ;
// Greater than Relational Operator
var res1 = a > b ;
print( ' \n Is a greater than b ? ' ) ;
print ( res1 ) ;
// Lesser than Relational Operator
var res2 = a < b ;
print( ' \n Is a lesser than b ? ' ) ;
print ( res2 ) ;
// Greater than or equal to Relational Operator
var res3 = a >= b ;
print( ' \n Is a greater than equal to b ? ' ) ;
print ( res3 ) ;
// Lesser than or equal to Relational Operator
var res4 = a <= b ;
print( ' \n Is a lesser than equal to b ? ' ) ;
print ( res4 ) ;
// Equal to Operator
var res5 = a == b ;
print( ' \n Is a equal to b ? ' ) ;
print ( res5 ) ;
// Not equal to Operator
var res6 = a != b ;
print( ' \n Is a not equal to b ? ' ) ;
print ( res6 ) ;
}
Output
Is a greater than b ?
false
Is a lesser than b ?
true
Is a greater than equal to b ?
false
Is a lesser than equal to b ?
true
Is a equal to b?
false
Is a not equal to b ?
true