可以使用 getOrDefault 方法。如果 Key 存在但 Value 为 Null,getOrDefault 方法会返回 defaultValue 的值。例如:

Map<String, String> map = new HashMap<>();
map.put('key', null);
String value = map.getOrDefault('key', 'default');
System.out.println(value); // 输出'default'

原文地址: https://www.cveoy.top/t/topic/m0Sh 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录