public static void testIfPresent() {
Map<String, Map<String, String>> map = new HashMap<>();
String firstKey = "hjz", secondKey = "lxk";
Map<String, String> childMap = new HashMap<>();
childMap.put("lxk", "sbj");
map.put("hjz", childMap);
ifPresent(map, firstKey, secondKey, System.out::print);
}
public static void ifPresent(Map<String, Map<String, String>> map, String firstKey, String secondKey, Consumer<String> consumer) {
ofNullable(map.get(firstKey)).ifPresent(childMap -> ofNullable(childMap.get(secondKey)).ifPresent(consumer));
本文轉自 小眼兒 部落格園部落格,原文連結:http://www.cnblogs.com/hujunzheng/p/8058474.html,如需轉載請自行聯系原作者