Javatpoint Logo
Javatpoint Logo

Java ConcurrentHashMap hashcode() Method

The hashcode() method of ConcurrentHashMap class returns the hash code value for this Map, i.e., the sum of, for each key-value pair in the map, key.hashCode() ^ value.hashCode().

Syntax

Parameter

No parameter is passed.

Returns

the hash code value for this map.

Throws

NullPointerException.

Example 1

Test it Now

Output:

import java.util.concurrent.*; 
  
 import java.util.*; 
  
public class ConcurrentHashMaphashcodeExample2 { 
  
    public static void main(String[] args) 
    { 
        HashMap mapcon 
            = new HashMap<>(); 
        mapcon.put("k1", 100); 
        mapcon.put("k2", 200); 
        mapcon.put("k3", 300); 
        mapcon.put("k4", 400); 
        System.out.println("HashMap values :\n " + mapcon.toString());  
        mapcon.computeIfAbsent("k5", k -> 200 + 300); 
        mapcon.computeIfAbsent("k6", k -> 60 * 10); 
        System.out.println("New HashMap after computeIfAbsent :\n "+ mapcon.hashCode()); 
    } 
}

Example 2

Test it Now

Output:






Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA