I am doing a simple application in which I am using a LinkedHashMap implementation of Map to store <contactName> and <contactNumber> pairs.
and i am implementing two kinds of search searchByName() and searchByNumber();
while searching by Name i can easily retrieve the results where as while searching through the number there is no direct way to do that according to what i know so far. So i used the following approach.
If anybody knows some other efficient way for doing the same please let me know.
Thanks in Advance!!! dinesh.
[ Added code tags - Jim ] [ January 01, 2007: Message edited by: Jim Yingst ]
Or, if you know that no key is ever the same as any value, then you can use just one map, with one forward and one backward mapping per key-value pair. In the case of telephone numbers and people's names, you're pretty safe; there's unlikely to be a "Mr 990-12345" or anyone whose number is "Jane Smith".
Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
That is interesting peter. I never thought of that. I like it.
To the OP, I don't think your technique even works. The valuset and the key set I do not think are guaranteed to be returned in the same order, nor are they guaranteed to iterate in the same order. I don't think.
Try using entry set.
There is another dirty approach like so;
[ January 02, 2007: Message edited by: Mr. C Lamont Gilbert ]
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
subject: Retrieval of Key through Values in a Map.