I have a list of maps mapList.
I'm iterating using nested for-loops to get a value.
Here's my imperative code:
for(Map<String, Object> stringObjectMap : mapList){
for(Map.Entry<String, Object> entry : stringObjectMap.entrySet()){
if("SubmittedBy".equalsIgnoreCase(entry.getKey().trim())){
// Logics to implement
}
}
}
Now, I'm trying to achieve it using Stream API.
I need to get a String value from one of the Maps which is associated with a key matches ignoring case to the string "SubmittedBy".
Here's my attempt:
String submittedBy = mapList.stream()
.filter(map -> map.entrySet().stream()
.filter(sub -> sub.getKey().equalsIgnoreCase("SubmittedBy")))
.findAny()
.get();
It produces a compile error saying bad return type. How I can fix it?
Bad return type in lambda expression:
Stream<Entry<String, Object>> cannot be converted to boolean