0% found this document useful (0 votes)
4 views2 pages

HashMap in Java

The document provides a Java program demonstrating the use of a HashMap, including creation, insertion, searching, iteration, and removal of key-value pairs. It shows how to add entries, check for the existence of keys, retrieve values, and iterate through the map. The example also illustrates updating a value and removing an entry from the HashMap.

Uploaded by

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

HashMap in Java

The document provides a Java program demonstrating the use of a HashMap, including creation, insertion, searching, iteration, and removal of key-value pairs. It shows how to add entries, check for the existence of keys, retrieve values, and iterate through the map. The example also illustrates updating a value and removing an entry from the HashMap.

Uploaded by

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

HashMap in Java

import [Link].*;

public class Hashing {


public static void main(String args[]) {
//Creation
HashMap<String, Integer> map = new HashMap<>();

//Insertion
[Link]("India", 120);
[Link]("US", 30);
[Link]("China", 150);

[Link](map);

[Link]("China", 180);
[Link](map);

//Searching
if([Link]("Indonesia")) {
[Link]("key is present in the map");
} else {
[Link]("key is not present in the map");
}

[Link]([Link]("China")); //key exists


[Link]([Link]("Indonesia")); //key doesn't exist

//Iteration (1)
for( [Link]<String, Integer> e : [Link]()) {
[Link]([Link]());
[Link]([Link]());
}

//Iteration (2)
Set<String> keys = [Link]();
for(String key : keys) {
[Link](key+ " " + [Link](key));
}
//Removing
[Link]("China");
[Link](map);

}
}

You might also like