前言 今天在查看力扣周赛385题解时,发现了几个我平时没注意的map方法,看了jdk相关的源码,感觉很巧妙,可以帮我节省代码,于是乎顺带着整个Map类的方法都过了一遍,下面是我看后整理的内容。 Map类中包括了以下方法: clear() compute(K,BiFunction computeIfAbsent(K,Function computeIfPresent(K,BiFunction containsKey(Object) containsValue(Object) entrySet() equals(Object) forEach(BiConsumer get(Object) getOrDefault(Object, V) hashCode() isEmpty() keySet() merge(K,V,BiFunction put(K,V) putAll(Map putIfAbsent(K,V) remove(Object) remove(Object,Object) replace(K,V,V) replace(K,V) replaceAll(BiFunction size() values() 方法详解 clear() 源码: /** * Removes all of the mappings from this map (optional operation). * The map will be empty after this call returns. * * @throws UnsupportedOperationException if the <tt>clear</tt> operation * is not supported by this map */void clear(); 功能:移除Map中所有的键值对。 compute...