Could some one please let me know how to add and read the elements from HashMap?
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):
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);
I am trying the following sample I am getting error
public class Test
public static void main(String args)
HashMap hashmap = new HashMap();
Can someone please let me know?
I tried running this code and it works fine. What error are you getting?
Thanks It works.