java stream find first match code example
Example 1: lambda loop java fetch first element
yourStream
.filter(/* your criteria */)
.findFirst()
.get();
Example 2: java 8 filter first
return dataSource.getParkingLots()
.stream()
.filter(parkingLot -> Objects.equals(parkingLot.getId(), id))
.findFirst()
.orElse(null);