×

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

  1. All these equality and relational operators are binary operators.
  2. 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.

  1. 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

Related Topics

Dart Built-in Data Types

A data type defines the type of value a variable can hold, such as integer, double, or string.  Dart supports two data types:  1. Built-in data types : These are the data...

1 minute read.

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...

3 minutes read.

Dart Basics

Dart, as earlier mentioned multiple times, is very similar to C, C++ and Java. It is an object-oriented, garbage collecting and class-based programming language. Let’s look further and see what Dart has...

10 minutes read.

Dart If-else statement

In the previous section, we studied about if statements in detail. If – block is executed when the condition evaluates to true, else if the condition evaluates to false, then...

1 minute read.

Dart Single-Page Application Architecture

In a single page application architecture, the source code for a single web page loads the entire application. The responsibility of building the user interface and requesting data from the...

2 minutes read.

Builder Classes in Dart

Before understanding builder classes, let us understand about Flutter that makes the best use of the builder classes. Flutter is actually not a programming language, it is a software development...

6 minutes read.

Abstract Classes in Dart

Abstract classes in Dart are those classes that only contain abstract methods  (methods that do not contain any implementation). These classes are specifically designed for the purpose of inheritance. We...

4 minutes read.

Dart - extends, with and implements Keywords

The application development in Dart programming language using the Flutter framework, regularly experience different usage of the implements, extends and with keywords. Dart has full support for inheritance that is...

5 minutes read.

Dart Generics

Dart Generics is similar to Dart collections, which are used to store homogeneous data. As we have discussed in Dart's features, it is a language with types being optional. By default,...

4 minutes read.

Lexical Scope and Closure

Lexical Scope : Lexical scope is a very important term in any programming language. It defines the scope of the variable based on the block it is contained inside. According to...

2 minutes read.

Dart Logical Operators

Logical operators are the operators that combine two or more conditions, and accordingly return a Boolean value : true or false. Assume the value of variable A is 25 and B...

2 minutes read.

Dart Object-Oriented Concepts

Dart is a programming language that supports object-oriented programming. It is focused on the objects that are real-world entities and supports all the concepts of OOPS, such as objects, classes,...

4 minutes read.

Dart Basic Program

Dart provides various convenient platforms to code and compile the program in Dart language. Some of them are: 1. Using IDE = Visual Studio code is a text editor with IDE....

3 minutes read.

Dart Maps

Map is an object-based data structure that associates keys and values that can be of any data type. Every key can occur only once, while the values can be used multiple...

5 minutes read.

Dart Break and Continue

Loop statements are used to change the normal sequence of flow of the program. Dart supports two types of loop control statements: Break StatementContinue Statement Break Statement : The ‘ break ’ statement is...

4 minutes read.

Dart Loops

Looping refers to repeating or reusing the same lines of code repeatedly until a particular test condition evaluates to true. It is also known as iterating.  It is effectively used when...

4 minutes read.

Typedef in Dart

In Dart, typedef is used to generate a function type that we can use as a type annotation for declaring variables and return types of the function type. An alias...

4 minutes read.

Dart Constants

Dart Constants are the objects or variables whose values can’t change or modify during the execution of the program. Their use case is when we want a particular value to...

2 minutes read.

Dart - Control Flow Statements

The control flow statements are used to define the control on the flow of the program. Dart programs are executed in sequential order i.e., the order in which the programming...

1 minute read.

Dart Keywords

Keywords are the reserved words of a programming language, and they have a special meaning that comes defined by the language. These cannot be used as an identifier, and all...

1 minute read.