// https://www.baeldung.com/java-stream-findfirst-vs-findany
public Customer getCustomerByName(String name){
return customers
.stream()
.filter(
c -> c.getName().equals(name)
)
.findFirst()
.orElseThrow(null); // There should be an exception here instead of null.
}
Comments