This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes HashMap problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "HashMap problem" Watch "HashMap problem" New topic
Author

HashMap problem

Shivkalyan Chavan
Greenhorn

Joined: May 29, 2008
Posts: 2
Hi,

In my application I put key, value pair using Hashmap. Later I use these values for sending mail. I am facing following question related problem..

1) Is the hashmap values are refreshed only when web server restarted?
2) Suppose I used index keys to retrieve values then evary time I use the same index value for that value or it get different value on random selection.
3) Is any alternative solution except HashTable to key and value pair..?

Please help to sort out these questions..

Regards,
Shivkalyan
Amit Ghorpade
Bartender

Joined: Jun 06, 2007
Posts: 2716
    
    6

Hi Shivkalyan Chavan, welcome to Javaranch,
I will answer your questions but will you please tell me first what do they have to do with servlets?
Please take a glance through the Ask good question link in my signature below.

The moderators will move it to a proper, I'll post my reply there.


SCJP, SCWCD.
|Asking Good Questions|
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37926
    
  22
Originally posted by Shivkalyan Chavan:
1) Is the hashmap values are refreshed only when web server restarted?
2) Suppose I used index keys to retrieve values then evary time I use the same index value for that value or it get different value on random selection.
3) Is any alternative solution except HashTable to key and value pair..?
  • 1: Don't know. Have you set up any refreshing code?
  • 2: Read the API for a Map. It is a "function": same input--->same output.
  • 3: Look up implementations of the Map interface. Most people use HashMap nowadays instead of Hashtable.

  • [ June 24, 2008: Message edited by: Campbell Ritchie ]
    Rob Spoor
    Sheriff

    Joined: Oct 27, 2005
    Posts: 19651
        
      18

    Originally posted by Shivkalyan Chavan:
    2) Suppose I used index keys to retrieve values then evary time I use the same index value for that value or it get different value on random selection.

    You get the same value each time, unless you overwrite the old value by another put operation.
    That's exactly how Maps work - they are a mapping (hence the name) from a key to a value. You as the programmer determine what the mappings will be, by issuing put operations. When you then use a get operation it will retrieve the value you have stored last with a put operation.

    Keep this in mind though:
    When you are using a HashMap or Hashtable, the equals and hashCode methods will be used to do the lookups. The hashCode value can never change, or you will not be able to retrieve the value. That's why String and Integer are excellent for keys - once created these objects never change.

    When you are using TreeMap the same holds for the compareTo method.


    SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
    How To Ask Questions How To Answer Questions
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: HashMap problem
     
    Similar Threads
    decoding binary arrays/boolean arrays
    SET function
    HashMap advance counter
    Which java Collections Shall i Use?
    dynamic parameters to java methods