I have a Map<String, Boolean>
with the following entries:
{‘John’:false,
'Mike':false,
'Tom':true,
'Harry':false,
'Bob': false}
I need to find the first entry and its index which has the value true. Here I should get Tom and 3 (say, index starts with 1).
I can iterate the map and get these values:
int itr=0;
for(Iterator<Map.Entry<String, Boolean>> entries = map.entrySet().iterator; entries.hasNext(); ) {
itr++;
Map.Entry<String, Boolean> entry = entries.next();
if(entry.getValue()) {
name = entry.getKey();
index = itr;
}
}
However, I am looking at a lambda expression for the same.