Java

Program to get the value of a specified key.

Program to get the value of a specified key.
import java.util.*;  
public class demo1 
{  
  public static void main(String args[]) 
  {  
  HashMap<Integer,String> hashmap= new HashMap<Integer,String>();
  hashmap.put(1, "C#");
  hashmap.put(2, "C++");
  hashmap.put(3, "Java");
  hashmap.put(4, "Python");
  hashmap.put(5, "Ruby");
    
  String str=(String)hashmap.get(4);    
  System.out.println("Value for key 3 is: " + str);
 }
}
Nikhil Juneja

Passionate software developer and technical contributor at TutorialsLink.