简体   繁体   中英

How to get particular key and value from Map

I have searched but could not find a way to print only single key, value pair for particular entry.

map.containsValue(value) or map.containsKey(key)

will only tell if particular value or key is available or not. I want to print that particular key, value pair if (value is available) In other link, They want to get the random value, if you do not know the key. Here I know key and value and want to print it for particular key and value.

There is no avalilable method in https://docs.oracle.com/javase/7/docs/api/java/util/Map.html to get Entity from map if there is any key or value available. Try below code if it help :

if (map.containsKey(key)) {
   Object value = map.get(key);
 System.out.println("Key : " + key +" value :"+ value);
 }

Access pair using Key

Operation on value if u want (optional)
myMap.put(s,value)
and for accessing whole map use Iterator of Map.Entry set

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM