I recently tried to filter trough a stream to check if a specific item was present. My first approach was the following:
return customers
.stream()
.filter(customer -> customer.getName().equals("Smith"))
.findFirst()
.isPresent();
But in my company uses sonar qube (https://www.sonarqube.org/) as a static code analysis tool. SQ suggested me a better solution for this:
return customers
.stream()
.anyMatch(
customer -> customer.getName().equals("Smith")
);