Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

HashMap getKeyByValue function

807601Mar 10 2008 — edited Mar 10 2008
Hi.

It looks to me like we do have the HashMap.containsValue(value) function that returns true if the map does contain that value, but we don't have a function that would tell us the key corresponding to that value. Doesn't it seem a bit ironic? I mean, they made containsValue() just to let us know that the value is in there, but it wouldn't return the key. We gotta iterate ourselves through the map in order to find the key. Isn't it what containsValue() does? Iterate through the map to find out if the value is in there or not? Would it have been so difficult to make a getKeyByValue function?

Am I missing something? I've gone through the API, and I can't seem to find any other way to get a key by it's value, except for iterating through the entire map.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 7 2008
Added on Mar 10 2008
7 comments
437 views