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);
}
}