zoukankan      html  css  js  c++  java
  • 【JAVA】哈希表HashMap中java8新增功能概述

    getOrDefault

    • getOrDefault(Object key, V defaultValue)

    • 如果存在key返回对应的value,否则返回defaultValue

    replaceAll

    • replaceAll(BiFunction<? super K, ? super V, ? extends V> function)

    • 以key为维度替换所有的value,替换逻辑在function中实现

    putIfAbsent

    • putIfAbsent(K key, V value)

    • 如果key存在则返回对应的value,否则将key和value添加到map中

    computeIfAbsent

    • computeIfAbsent(K key,Function<? super K, ? extends V> mappingFunction)

    • 如果key存在返回对应的value,如果不存在则通过function计算出value并放入map中

    computeIfPresent

    • computeIfPresent(K key,BiFunction<? super K, ? super V, ? extends V> remappingFunction)

    • 如果key存在则根据function计算一个新的value并新的value放入map,如果新value为null则从map中移除该key。

    compute

    • compute(K key,BiFunction<? super K, ? super V, ? extends V> remappingFunction)

    • 通过function计算key对应的newValue,newValue不为空则放入map,否则在key存在的情况下移除该key。

    merge

    • merge(K key, V value,BiFunction<? super V, ? super V, ? extends V> remappingFunction)

    • 基于key对应的oldValue和value通过function计算新的newValue,newValue不为空则放入map,否则从map中移除key。

    END

  • 相关阅读:
    [usaco]Cow Pedigrees
    组合数取模
    [usaco]Controlling Companies
    ubuntu g++ 升级
    膜拜
    Node.js权威指南 (2)
    Vue.js 开发环境的搭建
    src路径问题:./ 与 ../
    vscode vue代码提示错误
    H5 localStorage sessionStorage
  • 原文地址:https://www.cnblogs.com/anliux/p/12364653.html
Copyright © 2011-2022 走看看