• 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

suggetion needed

 
Ranch Hand
Posts: 242
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I need some suggestion to store my data.

I have my data as follows.

string1 1,2,3,6
string2 3,5,8
string3 9,10,7

These are the set of data which needs to be collected in a container(for example array,hashmap or hashset) and then can be used for further manupulation. Which is the best way to store the data? Thanks.
 
Gopu Akraju
Ranch Hand
Posts: 242
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To be more clear, keys would be string1, string2 etc... and values would be the "1,2,3" or "5,8,10,12" etc
 
Ranch Hand
Posts: 184
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
well if your require the data to be stored as Key-Value pairs then you have to go for some map like hashmap or treemap etc... which map to choose depends on what is the requirment of your application as each of the map implementation has its own benifits
 
Gopu Akraju
Ranch Hand
Posts: 242
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That means, I can have in HashMap, string1 as my key and values can be an array of integers like {1,2,4,5}?
 
Gopu Akraju
Ranch Hand
Posts: 242
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think hashtable would be a better choice as my key value would be a string and integer array as value pair. Thanks.
I tried one small example and it works. But my problem now is it allows multiple same key values. How do I come over as I can not allow such situation in my application. Thanks.
[ March 27, 2008: Message edited by: Gopu Akraju ]
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I think hashtable would be a better choice


A HashMap will do the same, except that HashTable is thread-safe. Yor argument does not justify the use of a HashMap

But my problem now is it allows multiple same key values.


What do you mean ? A map cannot contain duplicate keys. If you want to avoid overwriting the same key, you can call the containsKey method to check if the key already exist.
 
Gopu Akraju
Ranch Hand
Posts: 242
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, you are Right. I checked both hash table and hashmap and both are serving the purpose. I may have to remove any key-value pair. In that circumstance, which do youu recomend? Hash table would still a better choice for my case as I can not allow any NULL values. Am I right?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hash table would still a better choice for my case as I can not allow any NULL values. Am I right?


That's right, but you still have to check for null before setting the value, otherwise you'll get a NullPointerException.
 
Make yourself as serene as a flower, as a tree. And on wednesdays, as serene as this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic