K - keyV - valuepublic class WrappedNonAbsentMap<K,V> extends Object implements Map<K,V>
Map> map = new HashMap>();
List list = map.get(key);
if(list==null){
list = new ArrayList();
map.put(key, list);
}
list.add(e);
using this class, your code will be:
Supplier> supplier = new Supplier>(){
public List get(K key){
return new ArrayList();
}
};
Map> map0 = new HashMap>();
Map> map = WrapedNonAbsentMap.wrap(map0, supplier);
map.get(key).add(e);
Map,
HashMap,
WrappedNonAbsentMap| 限定符和类型 | 方法和说明 |
|---|---|
void |
clear() |
boolean |
containsKey(Object key) |
boolean |
containsValue(Object value) |
Set<Map.Entry<K,V>> |
entrySet() |
V |
get(Object key) |
V |
get(Object key,
Supplier<K,V> supplier) |
V |
getIfPresent(Object key) |
boolean |
isEmpty() |
Set<K> |
keySet() |
V |
put(K key,
V value) |
void |
putAll(Map<? extends K,? extends V> m) |
V |
putIfAbsent(K key,
V value) |
V |
remove(Object key) |
int |
size() |
Collection<V> |
values() |
static <K,V> WrappedNonAbsentMap<K,V> |
wrap(Map<K,V> map,
Supplier<K,V> supplier) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitcompute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, remove, replace, replace, replaceAllpublic boolean containsKey(Object key)
containsKey 在接口中 Map<K,V>public boolean containsValue(Object value)
containsValue 在接口中 Map<K,V>public static <K,V> WrappedNonAbsentMap<K,V> wrap(Map<K,V> map, Supplier<K,V> supplier)
Copyright © 2020. All rights reserved.