check if map contains key in java

check if map contains key in java
/**
 * @author lautturi.com
 * Java example: java check whether key is in hashmap map 
 */

import java.util.*;
import java.io.*;

public class Lautturi {
	public static void main(String[] args) {

		Map map = new HashMap();
		map.put("Apple", "21");
		map.put("Banana", "31");
		map.put("Cherry", "22");
		map.put("Orange", "54");
		String key = "Banana";
		
		if (map.containsKey(key)) {
		   System.out.println("Okay, there's a key");
		} else {
			System.out.println("No such key in the map");
		}
		
	}
}
Source‮.www:‬lautturi.com
Created Time:2017-09-02 21:37:32  Author:lautturi