0% found this document useful (0 votes)
7 views1 page

Java ConcurrentHashMap Example

The document presents a Java example demonstrating the use of ConcurrentHashMap, a thread-safe implementation of the Map interface. It shows how to declare a ConcurrentHashMap, add elements, retrieve values by key, and remove elements. The example includes output statements to display the values retrieved and the final state of the map after removal.

Uploaded by

hoangtu112201
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views1 page

Java ConcurrentHashMap Example

The document presents a Java example demonstrating the use of ConcurrentHashMap, a thread-safe implementation of the Map interface. It shows how to declare a ConcurrentHashMap, add elements, retrieve values by key, and remove elements. The example includes output statements to display the values retrieved and the final state of the map after removal.

Uploaded by

hoangtu112201
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

# ConcurrentHashMapExample

import [Link].*;

public class ConcurrentHashMapExample {


public static void main(String args[]) {

/* This is how to declare HashMap */


ConcurrentMap<Integer, String> hmap = new ConcurrentHashMap<Integer,
String>();

/*Adding elements to HashMap*/


[Link](12, "Chaitanya");
[Link](2, "Rahul");
[Link](7, "Singh");
[Link](49, "Ajeet");
[Link](3, "Anuj");

/* Get values based on key*/


String var= [Link](2);
[Link]("Value at index 2 is: "+var);
String var2= [Link](7);
[Link]("Value at index 7 is: "+var2);

/* Remove values based on key*/


[Link](3);

[Link](hmap);
}
}

You might also like