[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: HashMap Troubles
I tried following and both the string and reference to string prints the values correctly. Hope this is of some help:
----------------------------------------------------------------------
//HashMapExample
import java.util.*
public class HashMapExample
{
public static void main(String [] args)
{
HashMap hm = new HashMap();
//String values
String name = new String("name");
String my_name = new String("myName");
hm.put("name", "myName");
// String reference for the key
String home = new String("1000 North Spring, Atlanta GA");
hm.put("address", home);
// String reference for key and value
String ph = new String("phone");
String num = new String("180077777777");
hm.put(ph, num);
System.out.println(hm.get("name"));
System.out.println(hm.get("address"));
System.out.println(hm.get(ph));
}
}
"HashMapExample.java" 30 lines, 651 characters
XXXX/java/collect>javac HashMapExample.java
XXX/java/collect>java HashMapExample
myName
1000 North Spring, Atlanta GA
180077777777
"Deron Pardue" <dpardue@dspin.com> wrote:
> I'm trying to retrieve specific values from a HashMap.
>
>I can print the HashMap (using the toString() method) and see that I have key=value pairs, but when I try to retrieve a specific value using the get() method, I always get a null value returned. Am I using get() correctly?
>
>from instance, if I use map.put("name","myName") and print (using toString()) I get "name=myName"
>
>When I try the following:
> System.out.println(map.get("name"));
>
>I get null.
>
>Any clues?
>
>Thanks!
>
>Deron Pardue
>
>
>
--
ChandraShekhar Pendyala
__________________________________________________________________
Your favorite stores, helpful shopping tools and great gift ideas. Experience the convenience of buying online with Shop@Netscape! http://shopnow.netscape.com/
Get your own FREE, personal Netscape Mail account today at http://webmail.netscape.com/