Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Which one is better? Hash Map or Properties File

 
Santhosh Gowd
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • 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.
 
Gamini Sirisena
Ranch Hand
Posts: 378
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • 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
  • 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?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65227
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
wow that really helps. Thanks! @Bear.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic