Retrieving Hashmap value by comparing hashmap key

Program:

Hashmap.java

package com.ngdeveloper.com;

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…….!!!

494 total views, 1 views today

About: Mirthbees

Blogger, Innovator, Developer and Enterpreneur. Founder of GuruRecharge, Readymade online recharge script. Lead Developer in Bookrate.in