Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

2 key hash map Implementation...

Status
Not open for further replies.

patnim17

Programmer
Jun 19, 2005
111
US
Hello,
I have a programming requirement wherein I need to lookup for a value from a HashTable based on a Key. Let us call this Key as K1 and the value as Employee Name. So basically I have a HashTable with K1 as Key and Name as values.

Now, I need to introduce a new Key K2, with a one-to-one relation between K1 and K2. So I should be able to lookup using either K1 or K2 and I should get the values for all.
You can think of K1 and K2 as SSN and Employee ID within a company.

I can have another HashTable ofcourse, but is there a better and simpler way to implement this in java.

Patnim

 
Well, I don't think there's a simpler way than two Hastables or one HastTable with duplicated values.

Now the big question is if there's a better sollution and I guess it will depend on how you're handling the data. I'd expect this data to be in a database so the access would be done depending on the key field.

But being in memory, it will depend on what kind of operations you want to perform: search, modification ...

Cheers,
Dian

 
What you want is a relational database

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
We have this data in the database. Its just that in the apllication we cache this information for quick lookup. THe data does not change very often..so..

Anyways..I guess 2 HashTable implementation is what sounds like a solution.

Pat
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top