Dart double hashCode
Syntax & Examples

double.hashCode property

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.


Syntax of double.hashCode

The syntax of double.hashCode property is:

 int hashCode 

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

Return Type

double.hashCode returns value of type int.



✐ Examples

1 Get the hash code of a string

In this example,

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

Dart Program

void main() {
  String str = 'Hello';
  int hash = str.hashCode;
  print('Hash code of $str: $hash');
}

Output

Hash code of 'Hello': 180399535

2 Get the hash code of a list

In this example,

  1. We create a list of integers numbers.
  2. We use the hashCode property to get its hash code.
  3. We then print the hash code to standard output.

Dart Program

void main() {
  List<int> numbers = [1, 2, 3, 4, 5];
  int hash = numbers.hashCode;
  print('Hash code of numbers list: $hash');
}

Output

Hash code of numbers list: 549342870

3 Get the hash code of a map

In this example,

  1. We create a map ages with key-value pairs.
  2. We use the hashCode property to get its hash code.
  3. We then print the hash code to standard output.

Dart Program

void main() {
  Map<String, int> ages = {'Alice': 30, 'Bob': 25, 'Charlie': 35};
  int hash = ages.hashCode;
  print('Hash code of ages map: $hash');
}

Output

Hash code of ages map: 77957922

Summary

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.