Dart Tutorials

Dart List hashCode
Syntax & Examples

Syntax of List.hashCode

The syntax of List.hashCode property is:

 int hashCode 

This hashCode property of List the hash code for this object.

Return Type

List.hashCode returns value of type int.



✐ Examples

1 Get hash code of a string

In this example,

  1. We create a string 'Hello'.
  2. We then use the hashCode property to get its hash code.
  3. We print the hash code to standard output.

Dart Program

void main() {
  int hashCodeValue = 'Hello'.hashCode;
  print(hashCodeValue);
}

Output

180399535

2 Get hash code of an integer

In this example,

  1. We create an integer 123.
  2. We then use the hashCode property to get its hash code.
  3. We print the hash code to standard output.

Dart Program

void main() {
  int hashCodeValue = 123.hashCode;
  print(hashCodeValue);
}

Output

123

3 Get hash code of a boolean

In this example,

  1. We create a boolean true.
  2. We then use the hashCode property to get its hash code.
  3. We print the hash code to standard output.

Dart Program

void main() {
  int hashCodeValue = true.hashCode;
  print(hashCodeValue);
}

Output

519018

Summary

In this Dart tutorial, we learned about hashCode property of List: the syntax and few working examples with output and detailed explanation for each example.