Map
Map
SubClass should implements non-arguments constructor and constructor(Map)
This interface takes the place of the Dictionary class, which was a totally abstract class rather than an interface.
Note: great care must be exercised if mutable objects are used as map keys.
The behavior of a map is not specified if the value of an object is changed in a manner that affects equals comparisons while the object is a key in the map.
A special case of this prohibition is that it is not permissible for a map to contain itself as a key.
While it is permissible for a map to contain itself as a value, extreme caution is advised: the equals and hashCode methods are no longer well defined on such a map.
1 | public interface Map<K,V> { |
- computeIfAbsent(key,func(key))
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18get(key) == null ?
newValue=func(key) != null ?
put(key,newValue);
return newValue;
:
:return get(key);
```
- computeIfPresent(key,func(key,get(key)))
```java
get(key) != null ?
newValue = func(key,get(key)) !=null ?
put(key,newValue);
return newValue;
:
remove(key)
return null;
:
return null;
小计
| method | func |
|---|---|
| compute | 先计算,新值不空加入 |
| computeIfAbsent | 旧值空则计算,新值不空加入 |
| computeIfPresent | 旧值不空则计算,新值不空加入 |
add-ons(FunctionalInterface)
Function
1 | /** |
-------------再接再厉更进一步---------------