Return a customer with stream function

PHOTO EMBED

Sat Jan 29 2022 09:05:11 GMT+0000 (Coordinated Universal Time)

Saved by @Shuhab

    // 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.
    }
content_copyCOPY