0
Hashmap key in java
How to get the key of known value using HashMap in java?
3 Respostas
0
HBhZ_C yes. That is literally what I answered. Visit the link I mentioned in my previous answer. The top answer gives some solutions. I recommend you read that answer, then check out each collection/method mentioned in the answer so that you know what they do. And then attempt again to find a solution to your problem.
+ 1
I don't know why you would want to do that, because there can be multiple keys mapping to the same value. Anyways, here is a useful answer I found
https://stackoverflow.com/questions/1383797/java-hashmap-how-to-get-key-from-value
As said in the top answer of the linked question, you will need to maintain 1:1 relationship, that is, 1 key mapping to 1 value, because if multiple values map to the same value, then which key should the program return? An ideal solution could be making a function to add a key value pair, and in that function you can check if the key already exists in the hash map, and accordingly give suitable errors.
+ 1
It was a method in java HashMap to get the value given its key but the inverse is it possible to give the value for unknown key and get its key XXX .