What is AbstractMap hashcode() in Java?

Overview

The hashcode() method of the AbstractMap class is used to get the hash code value for the map.

The default hash code of a map is defined to be the sum of the hash codes of each entry in the map’s entrySet view.

Note: Refer to What is the hashCode method in Java? to learn more about hashcode in Java.

Syntax

public int hashCode()

Parameters

The method has no parameters.

Return value

The method returns the hash code value.

Code example

Let’s look at the code below:

import java.util.*;
public class Main{
public static void main(String[] args) {
AbstractMap<String, String> abstractMap = new HashMap<>();
abstractMap.put("hello-1", "Educative");
abstractMap.put("hello-2", "edpresso");
System.out.println(abstractMap.hashCode());
}
}

Code explanation

  • Line 5: We define an abstract map. The abstract map has the implementation of the hash map.
  • Lines 6-7: Entries are added to the map using the put() method.
  • Line 9: The hash code of the map is obtained by invoking the hashCode() method and printed.

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved