Dart double operator-equal-to
Syntax & Examples


double.operator-equal-to operator

The equality operator checks if the given value is equal to another value and returns true if they are equal; otherwise, it returns false.


Syntax of double.operator-equal-to

The syntax of double.operator-equal-to operator is:

operator ==(dynamic other) → bool

This operator-equal-to operator of double the equality operator.

Parameters

ParameterOptional/RequiredDescription
otherrequiredthe value to compare with


✐ Examples

1 Example with numeric values

In this example,

  1. We create two numeric values numValue1 and numValue2 with the same value 10.
  2. We then use the equality operator == to check if numValue1 is equal to numValue2.
  3. We print the comparison result to standard output.

Dart Program

void main() {
  num numValue1 = 10;
  num numValue2 = 10;
  bool isEqual = numValue1 == numValue2;
  print('Is $numValue1 equal to $numValue2: $isEqual');
}

Output

Is 10 equal to 10: true

2 Example with string values

In this example,

  1. We create two string values str1 and str2 with values 'Hello' and 'hello' respectively.
  2. We then use the equality operator == to check if str1 is equal to str2 (case-sensitive).
  3. We print the comparison result to standard output.

Dart Program

void main() {
  String str1 = 'Hello';
  String str2 = 'hello';
  bool isEqual = str1 == str2;
  print('Is $str1 equal to $str2: $isEqual');
}

Output

Is 'Hello' equal to 'hello': false

3 Example with list values

In this example,

  1. We create two lists list1 and list2 with the same integer elements [1, 2, 3].
  2. We then use the equality operator == to check if list1 is equal to list2.
  3. We print the comparison result to standard output.

Dart Program

void main() {
  List<int> list1 = [1, 2, 3];
  List<int> list2 = [1, 2, 3];
  bool isEqual = list1 == list2;
  print('Is $list1 equal to $list2: $isEqual');
}

Output

Is [1, 2, 3] equal to [1, 2, 3]: true

Summary

In this Dart tutorial, we learned about operator-equal-to operator of double: the syntax and few working examples with output and detailed explanation for each example.