Could some one please let me know how to add and read the elements from HashMap?
Thanks
-
how to add the elements in the Hashmap (4 messages)
- Posted by: janaki bansal
- Posted on: January 14 2004 11:27 EST
Threaded Messages (4)
- how to add the elements in the Hashmap by Alan Choy on January 14 2004 11:36 EST
- how to add the elements in the Hashmap by janaki bansal on January 14 2004 13:55 EST
-
how to add the elements in the Hashmap by Shreeram Iyer on January 15 2004 09:37 EST
- how to add the elements in the Hashmap by janaki bansal on January 15 2004 11:52 EST
-
how to add the elements in the Hashmap by Shreeram Iyer on January 15 2004 09:37 EST
- how to add the elements in the Hashmap by janaki bansal on January 14 2004 13:55 EST
-
how to add the elements in the Hashmap[ Go to top ]
- Posted by: Alan Choy
- Posted on: January 14 2004 11:36 EST
- in response to janaki bansal
This is simple. HashMap stores key-value pair (both key and value must be an Object).
In order to store a key-value (assume ref is the reference to a HashMap):
ref.put(key, value);
In order to retrieve a value with a key (you can always cast the return value if you know what specified type it is):
Object value = ref.get(key); -
how to add the elements in the Hashmap[ Go to top ]
- Posted by: janaki bansal
- Posted on: January 14 2004 13:55 EST
- in response to Alan Choy
I am trying the following sample I am getting error
import java.lang.*;
import java.util.*;
public class Test
{
public static void main(String[] args)
{
HashMap hashmap = new HashMap();
hashmap.put("type", "INTERACTION_TYPE");
hashmap.put("code", "PHONE");
hashmap.put("description", "PHONE");
}
}
Can someone please let me know?
Thanks -
how to add the elements in the Hashmap[ Go to top ]
- Posted by: Shreeram Iyer
- Posted on: January 15 2004 09:37 EST
- in response to janaki bansal
I tried running this code and it works fine. What error are you getting?
-SI -
how to add the elements in the Hashmap[ Go to top ]
- Posted by: janaki bansal
- Posted on: January 15 2004 11:52 EST
- in response to Shreeram Iyer
Thanks It works.