The syntax of Map.hashCode property is:
int hashCode
This hashCode property of Map the hash code for this object.
Map.hashCode returns value of type int
.
In this example,
str
with the value 'Hello, world!'.hashCode
property of the string.void main() {
String str = 'Hello, world!';
int hashCode = str.hashCode;
print('Hash code of str: $hashCode');
}
Hash code of str: 287797974
In this example,
number
with the value 42.hashCode
property of the integer.void main() {
int number = 42;
int hashCode = number.hashCode;
print('Hash code of number: $hashCode');
}
Hash code of number: 42
In this example,
list
containing strings 'apple', 'banana', and 'cherry'.hashCode
property of the list.void main() {
List<String> list = ['apple', 'banana', 'cherry'];
int hashCode = list.hashCode;
print('Hash code of list: $hashCode');
}
Hash code of list: 507029333
In this Dart tutorial, we learned about hashCode property of Map: the syntax and few working examples with output and detailed explanation for each example.