I am trying to find Friend by firstName and lastName using stream. Is it possible to return object from this stream? Like friend with that name and lastname? Because now return is mismatched.
@Override
public Friend findFriend(String firstName, String lastName) throws FriendNotFoundException {
if (firstName == null || lastName ==null) {
throw new IllegalArgumentException("There is no parameters");
}
List<Friend> result = friends.stream()
.filter(x -> (firstName.equals(x.getFirstName())) &&
(lastName.equals(x.getLastName()))))
.collect(Collectors.toList());
return result;
findAny()orfindFirst()instead ofcollect().