Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

HashMap problem

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 2856
10
Firefox Browser Fedora Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Marshal
Posts: 69869
278
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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 ]
     
    Sheriff
    Posts: 21972
    106
    Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator

    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.
     
    For my next trick, I'll need the help of a tiny ad ...
    Thread Boost feature
    https://coderanch.com/t/674455/Thread-Boost-feature
      Bookmark Topic Watch Topic
    • New Topic