I have a for loop for a list that checks whether or not index values exist in the db.
Simply if any value doesn't exist, it immediately returns false.
public boolean exists(List<String> keys) {
for(String key: keys) {
boolean exists = service.existsByKey(key);
if(!exists) return false;
}
return true;
}
I tried to change it to java 8 foreach, but it doesn't work as expected.
keys.stream().forEach(k -> {
boolean exists = service.existsByKey(k);
if(!exists) return false;
});
Am I missing something? Why doesn't it go in if(!exists)
staetment in forEach()
?