File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes hashmap Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "hashmap" Watch "hashmap" New topic


tom brownlee

Joined: Aug 14, 2001
Posts: 28
how can i put an object as the value in a hashmap
hashMap.put("some key" , Object);
in my code i have a user enter in a jewel color where it should look up the hash table with the jewel colour as the key returning the jewel as an object in which i can then manipulate with other methods.
how do i do this?
Marilyn de Queiroz

Joined: Jul 22, 2000
Posts: 9059
hashMap.put("some key" , new Object());

"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
William Barnes
Ranch Hand

Joined: Mar 16, 2001
Posts: 986

You seem to be asking to different questions at the same time. First you say you want to "put" a value, this implies you wish to assign an value into the hashmap. Than you say you want to "look up", which implies you want to extract a value.
The answer to assigning a value was posting by Marilyn.
To extract a value you can the "get" method.

Please ignore post, I have no idea what I am talking about.
I agree. Here's the link:
subject: hashmap
It's not a secret anymore!