*
The moose likes Beginning Java and the fly likes suggetion needed Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "suggetion needed" Watch "suggetion needed" New topic
Author

suggetion needed

Gopu Akraju
Ranch Hand

Joined: Jan 13, 2008
Posts: 242
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

Joined: Jan 13, 2008
Posts: 242
To be more clear, keys would be string1, string2 etc... and values would be the "1,2,3" or "5,8,10,12" etc
abhishek pendkay
Ranch Hand

Joined: Jan 01, 2007
Posts: 184
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


The significant problems we face cannot be solved by the same level of thinking which created them – Einstein
SCJP 1.5, SCWCD, SCBCD in the making
Gopu Akraju
Ranch Hand

Joined: Jan 13, 2008
Posts: 242
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

Joined: Jan 13, 2008
Posts: 242
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 ]
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

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.


[My Blog]
All roads lead to JavaRanch
Gopu Akraju
Ranch Hand

Joined: Jan 13, 2008
Posts: 242
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

Joined: Nov 24, 2005
Posts: 14687
    
  16

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: suggetion needed
 
Similar Threads
Database structure
Upload Picture - Path or Binary?
using database at remote location
Shopping Web project
How to compress text data before storing it in database