Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 893
Hitesh Kumar Avatar asked Jun 20 '16 11:06

Hitesh Kumar


People also ask

How do I print a specific value in a HashMap?

Print from the HashMap Reference This is the most basic and easiest method to print out HashMap in java. Pass the HashMap reference to the System. out. println, and the HashMap will output the key-value of the elements enclosed in curly brackets.


1 Answers

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);
 }
like image 83
sauumum Avatar answered Sep 24 '22 05:09

sauumum