// 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.
    }
                
            Preview:
        downloadDownload PNG
        downloadDownload JPEG
                        downloadDownload SVG
        
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter