0
如何檢查密鑰是否映射到HashMap?Java:如何檢查密鑰是否映射到HashMap?
這裏是我的代碼:
currencyMap = new HashMap<String, String>();
currencyMap.put("USD", "US Dollar");
currencyMap.put("EUR", "Euro");
currencyMap.put("GBP", "British Pound Sterling");
currencyMap.put("JPY", "Japanese Yen");
currencyMap.put("CAD", "Canadian Dollar");
currencyMap.put("AUD", "Australian Dollar");
String checkCurrency = "CHF"; // Swiss Franc
// List Keys
for (String key : currencyMap.keySet()) {
String value = currencyMap.get(key);
System.out.println(key + " = " + value);
}