lambda表达式有2种形式:
(parameters)-> expression
(parameters)-> {statements;}
比如遍历多层级map:
answerMap格式:Map<String,Map<String,Map<String,Object>>> (三层,每层的key都是String类型),要获取最内层的value值。
如果用for循环,每次获取key值数组,再遍历Key获取value:
for(String oneKey:answerMap.keySet()){
for(String twoKey:answerMap.get(oneKey).keySet()){
for(String threeKey:answerMap.get(oneKey).get(twoKey).keySet()){
Object threeValue = answerMap.get(oneKey).get(twoKey).get(threeKey);}}}
如果用lambda表达式:
answerMap.forEach((oneKey,oneValue) ->{
oneValue.forEach((twoKey,twoValue) ->{
twoValue.forEach((ques,answer) ->{
}
});
});
这里的answer其实就是上面获取的threeValue