点击运行
import java.util.HashMap; public class Main { public static void main(String[] args) { // 创建一个 HashMap HashMap
prices = new HashMap<>(); // 往HashMap中添加映射关系 prices.put("Shoes", 200); prices.put("Bag", 300); prices.put("Pant", 150); System.out.println("HashMap: " + prices); // 重新计算鞋加上10%的增值税后的价值 int shoesPrice = prices.computeIfPresent("Shoes", (key, value) -> value + value * 10/100); System.out.println("Price of Shoes after VAT: " + shoesPrice); // 输出更新后的HashMap System.out.println("Updated HashMap: " + prices); } }
运行结果 :
正在执行...