------Java Training, Android training, iOS training,. NET training, look forward to communicating with you! -------
The key value in HashMap is unique, but value is not unique; the same value may return more than one key
Here's an example: Find out that value is a key of "value"
1 ImportJava.util.HashMap;2 ImportJava.util.Iterator;3 ImportJava.util.Map;4 ImportJava.util.Set;5 Public classHashmapkey {6 Public Static voidMain (String[]args) {7String value = "Map";8map<string,string> map =NewHashmap<string,string> ();//HashMap9Map.put ("0", "what");//Add ValueTenMap.put ("1", value); OneMap.put ("2", "ASDF"); AMap.put ("3", value); -set<string> mapset = Map.keyset ();//gets the set of all key values for the set -Iterator<string> itor = Mapset.iterator ();//get iterator traversal of key the while(Itor.hasnext ()) {//The next value exists -String key = Itor.next ();//Current key value - if(Map.get (key). Equals (value)) {//gets the value compared to the known value -System.out.println ("The key you're looking for:" +key);//equal output key + } - } + } A}
The result is:
The key:1 you're looking for. Key:3
Dark Horse programmer--get key value by HashMap value