The `hashCode` property returns the hash code for an object in Dart. This hash code is used for various purposes such as hash-based collections.
The syntax of double.hashCode property is:
int hashCode
This hashCode property of double the hash code for this object.
double.hashCode returns value of type int
.
In this example,
str
with the value 'Hello'.hashCode
property to get its hash code.void main() {
String str = 'Hello';
int hash = str.hashCode;
print('Hash code of $str: $hash');
}
Hash code of 'Hello': 180399535
In this example,
numbers
.hashCode
property to get its hash code.void main() {
List<int> numbers = [1, 2, 3, 4, 5];
int hash = numbers.hashCode;
print('Hash code of numbers list: $hash');
}
Hash code of numbers list: 549342870
In this example,
ages
with key-value pairs.hashCode
property to get its hash code.void main() {
Map<String, int> ages = {'Alice': 30, 'Bob': 25, 'Charlie': 35};
int hash = ages.hashCode;
print('Hash code of ages map: $hash');
}
Hash code of ages map: 77957922
In this Dart tutorial, we learned about hashCode property of double: the syntax and few working examples with output and detailed explanation for each example.