public class MapDemo {
public static void main(String[] args) {
Map<String,Object> m = new HashMap<String,Object>();
Object o = m.getOrDefault("heloo", "根本就没有,但是给它默认的我");
System.out.println(o);
m.put("1", "Kevin");
m.put("2", "Mart");
m.put("3", "Keety");
Collection<Object> c = m.values();
Object[] arr = c.toArray();
System.out.println(Arrays.toString(arr));
BiConsumer<String, Object> action = new BiConsumer<String, Object>() {
@Override
public void accept(String t, Object u) {
System.out.println("key:"+t+",value:"+u);
}
};
m.forEach(action);
BiFunction<Object,Object,Object> function = new BiFunction<Object,Object,Object>(){
@Override
public Object apply(Object t, Object u) {
return t +":"+u;
}
};
Object o1 = m.merge("2", "do job", function);
System.out.println(o1);
BiFunction<String, Object, Object> remappingFunction = new BiFunction<String,Object,Object>(){
@Override
public Object apply(String t, Object u) {
System.out.println("-----"+u);
return null;
}
};
Object o2 = m.compute("1", remappingFunction);
System.out.println("o2-->"+o2);
}
}