Return from lambda forEach() in java
The return there is returning from the lambda expression rather than from the containing method. Instead of forEach you need to filter the stream: players.stream().filter(player -> player.getName().contains(name)) .findFirst().orElse(null); Here filter restricts the stream to those items that match the predicate, and findFirst then returns an Optional with the first matching entry. This looks less efficient … Read more