• 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

相关文章:

  • 2021-10-20
  • 2021-09-05
  • 2021-08-26
  • 2021-07-27
  • 2021-10-12
  • 2022-12-23
  • 2022-01-19
  • 2022-12-23
猜你喜欢
  • 2021-04-14
  • 2021-11-27
  • 2021-05-08
  • 2021-08-20
  • 2022-02-15
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案