public class Unite8_MapTest1 {
public static void main(String[] args) {
// TODO 自动生成的方法存根
Map a = new HashMap();
//put(a,b)中a是key,b是value
a.put(2, "nice");
a.put(5, "to");
a.put(8, "meet");
a.put(10, "you");
//replace()是替换的意思,找到与key相同的,替换value值
a.replace(2,"good");
//输出的时候是根据key的大小,从小到大排序
System.out.println(a);
//a.merge(5, "nice", (o1,o2) -> (Integer)o1 + (Integer)o2);
//System.out.println(a);
//通过computeIfAbsent(a,b); a是key,b是value,若集合中没有key,则新建一个元素加入到集合中
a.computeIfAbsent("meet", key -> ((String)key).length());
System.out.println(a);
// a.computeIfPresent(2, (key,value) -> (Integer)key * (Integer)value);
System.out.println(a);
}