美文网首页
prices.merge

prices.merge

作者: felixfeijs | 来源:发表于2021-04-14 09:22 被阅读0次
public static void main(String[] args) {
    //创建一个HashMap
    HashMap<String, Integer> prices = new HashMap<>();

    // 往 HashMap 插入映射
    prices.put("Shoes", 200);
    prices.put("Bag", 300);
    prices.put("Pant", 150);
    System.out.println("HashMap: " + prices);

    int returnedValue = prices.merge("Shirt", 100, (oldValue, newValue) -> oldValue + newValue);
    System.out.println("Price of Shirt: " + returnedValue);

    // 输出更新后的 HashMap
    System.out.println("Updated HashMap: " + prices);
    }

相关文章

网友评论

      本文标题:prices.merge

      本文链接:https://www.haomeiwen.com/subject/lceclltx.html