The syntax of String.hashCode property is:
int hashCode
This hashCode property of String returns a hash code derived from the code units of the string.
String.hashCode returns value of type int
.
In this example,
str
with the value 'Hello'.hashCode
property of the string.hashCode
.void main() {
String str = 'Hello';
int hashCode = str.hashCode;
print('Hash code of $str: $hashCode');
}
Hash code of Hello: 180399535
In this example,
str
with the value 'ABCDEF'.hashCode
property of the string.hashCode
.void main() {
String str = 'ABCDEF';
int hashCode = str.hashCode;
print('Hash code of $str: $hashCode');
}
Hash code of ABCDEF: 463689234
In this example,
str
with the value 'Lorem ipsum'.hashCode
property of the string.hashCode
.void main() {
String str = 'Lorem ipsum';
int hashCode = str.hashCode;
print('Hash code of $str: $hashCode');
}
Hash code of Lorem ipsum: 21565321
In this Dart tutorial, we learned about hashCode property of String: the syntax and few working examples with output and detailed explanation for each example.