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

HashMap in Java

The document provides a Java program that demonstrates the use of HashMap for creating, inserting, searching, iterating, and removing key-value pairs. It shows how to handle duplicate keys, check for key existence, and iterate through the map using different methods. The program includes examples of output for each operation performed on the HashMap.

Uploaded by

Sagar Satav
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)
2 views2 pages

HashMap in Java

The document provides a Java program that demonstrates the use of HashMap for creating, inserting, searching, iterating, and removing key-value pairs. It shows how to handle duplicate keys, check for key existence, and iterate through the map using different methods. The program includes examples of output for each operation performed on the HashMap.

Uploaded by

Sagar Satav
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