Retrieving Hashmap value by comparing hashmap key

Program:

Hashmap.java

package com.javadomain.in;

import java.util.HashMap;
import java.util.Map.Entry;

public class Hashmap {
	public static void main(String[] args) {
		String keyword="super";
		HashMap<String, String> myMap = new HashMap<String, String>();
		myMap.put("super", "java keyword");
		myMap.put("array_merge", "php array function");
		for (Entry<String, String> pair : myMap.entrySet()) {
			if(pair.getKey().equalsIgnoreCase(keyword)){
		       System.out.println(keyword+" is: " + pair.getValue());
		      }
		  }
	}

}

 

Output:

super is: java keyword

Thanks for reading this post…….!!!

406 total views, 2 views today

Leave a Reply

Your email address will not be published. Required fields are marked *