HashMap 효율적으로 사용하기
HashMap의 Key, Value 출력
//create a map in java 11
var productPrice = new HashMap<String, Double>();
//or in java 8
Map<String, Double> productPrice = new HashMap<>();
// add value
productPrice.put("Rice", 6.9);
productPrice.put("Flour", 3.9);
productPrice.put("Sugar", 4.9);
productPrice.put("Milk", 3.9);
productPrice.put("Egg", 1.9);
//get value
Double egg = productPrice.get("Egg");모든 Key값 출력
Set<String> keys = productPrice.keySet();
//print all the keys
for (String key : keys) {
System.out.println(key);
}모든 Value값 출력
Key, Value 함께 출력
Key 중복 확인
computeIfAbsent() VS puIfAbsent()
computeIfPresent() VS compute()
getOrDefault()
Last updated