Java中map.getOrDefault()方法的使用
HashMap<String, String> map = new HashMap<>(); map .put( "name" , "cookie" ); map .put( "age" , "18" ); map .put( "sex" , "女" ); String name = map .getOrDefault( "name" , "random" ); System.out.println(name); // cookie,map中存在name,获得name对应的value int score = map .getOrDefault( "score" , 80 ); System.out.println(score); // 80,map中不存在score,使用默认值80 在这里看到的: https://blog.csdn.net/m0_37827190/article/details/106223703?utm_medium=distribute.pc_category.none-task-blog-hot-11.nonecase&depth_1-utm_source=distribute.pc_category.none-task-blog-hot-11.nonecase&request_id=### 来源: oschina 链接: https://my