Java tutorial
//package com.java2s; import java.util.Map; public class Main { /** * Returns the value for key in dictionary as a string or null if no value * is defined for the key. * * @param dict * Dictionary that contains the key, value pairs. * @param key * Key whose value should be returned. * @return Returns the string value for key in dict. */ public static String getString(Map<String, Object> dict, String key) { return getString(dict, key, null); } /** * Returns the value for key in dictionary as a string or the given default * value if no value is defined for the key. * * @param dict * Dictionary that contains the key, value pairs. * @param key * Key whose value should be returned. * @param defaultValue * Default value to return if the key is undefined. * @return Returns the string value for key in dict. */ public static String getString(Map<String, Object> dict, String key, String defaultValue) { Object value = dict.get(key); if (value == null) { return defaultValue; } else { return value.toString(); } } }