3:42 pm - Sunday November 18, 9742

HashMap Example program for get(Object key)

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044
/**
*@author:candidjava
*@description:HashMap Example Program for get(Object key)
**/

import java.util.HashMap;

public class Get
{
public static void main(String[] args)
{
// Create a HashMap with three key/value pairs.
HashMap hm = new HashMap();
hm.put("One", new Integer(1));
hm.put("Two", new Integer(2));
hm.put("Three", new Integer(3));
System.out.ptintln("HashMap:" +hm);
// Get the value associated with the key "Three".
Object v = hm.get("Three");
if (v != null)
{
System.out.println("The value associated with \"Three\" is " +
v);
}
else
{
System.out.println("There is no key named \"Three\" " +
"in the HashMap.");
}
}
}

output

The value associated with Three is 3

Filed in: Z-A All Java Codes

Comments are closed.