How to get Key from Value in Hashtable, HashMap or Map in Java


It's not easy to get key from value in Hashtable or HashMap, as compared to getting value from key, because Hash Map or Hashtable doesn't enforce one to one mapping between key and value inside Map in Java. infact Map allows same value to be mapped against multiple keys inside HashMap, Hashtable or any other Map implementation. What you have in your kitty is Hashtable.containsValue(String value) or Hashtable.containsKey(String key) to check whether key or value exists in Hashtable or not, but some time we want to retrieve value from Map corresponding to any key and there is no API method to do in Map. We can still do this, but it highly depends data in your Map because Hashtable and HashMap both allows duplicate values mapped to different key. In this Java tutorial, we will see example of how to get key from value in Hashtable in Java.
Read more »

0 Response to "How to get Key from Value in Hashtable, HashMap or Map in Java"

Posting Komentar