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) → boolThis operator-equal-to operator of double the equality operator.
Parameters
| Parameter | Optional/Required | Description |
|---|---|---|
other | required | the value to compare with |
✐ Examples
1 Example with numeric values
In this example,
- We create two numeric values
numValue1andnumValue2with the same value 10. - We then use the equality operator
==to check ifnumValue1is equal tonumValue2. - 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,
- We create two string values
str1andstr2with values 'Hello' and 'hello' respectively. - We then use the equality operator
==to check ifstr1is equal tostr2(case-sensitive). - 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,
- We create two lists
list1andlist2with the same integer elements [1, 2, 3]. - We then use the equality operator
==to check iflist1is equal tolist2. - 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.