• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Which one is better? Hash Map or Properties File

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a set of key value pairs. which one is better to use? Hash map or properties file and why? I need to use these key value pairs in a single java class only and the set is a bit large.
 
Ranch Hand
Posts: 378
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
since your requirement seems to be only to support a large set of data I guess it would be
easier to put in to a properties file. What I am thinking is that coding all of these values will
be very tedious. However there may be many ways how this can be accomplished.


Also if these values need to be changed from time to time properties file could be the way to go.
If these values should not be changed easily, putting in a property file may not be good.
 
Santhosh Gowd
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
no, i do not need to change these values. the values remain static. Any other way to go? I am processing this data while navigating between two jsp pages.
 
Marshal
Posts: 28226
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you have a set of key-value pairs then HashMap is the obvious thing to use. If those pairs have to come from an external file where they live permanently, then Properties would be the thing to use, but it sounds like that isn't the case. So use HashMap.

If you use Properties then readers of your code are going to assume that your data comes from an external file, because that's what Properties is for. So if your data doesn't come from an external file, then don't use Properties or you are going to confuse people.
 
Santhosh Gowd
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is my situation- I am navigating between to jsps, and i am calling a method there by a class in between. This method uses a fixed set of key-value pairs. So every time i should initialize this hash map, just like another variable. So this wouldn't be an overhead? as the set of values is a bit large. How does the property file works? It is also loaded each time?
 
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If the values won't change, loading them for each individual request is rather ridiculous. Employ a context listener to create the map once at startup, and store it in the application context where it can be accessed by all web app resources.

Whether you load it from a properties file or in code is rather moot. Choose which approach makes the most sense for code clarity.
 
Santhosh Gowd
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
wow that really helps. Thanks! @Bear.
 
reply
    Bookmark Topic Watch Topic
  • New Topic