0

I want to get the property of any object matching the filter() of the stream, but I am unable to.

transactionsList.stream()
    .filter(transaction -> transaction.getPayerIban() != null)
    .findFirst()
    //Here I get an Optional<Object>
    .ifPresent()
    .map(Transaction::getName)

I don't know what to do inside the .ifPresent() stream operation, but I want to get any transaction name of the matching transactions

1 Answer 1

2

Remove the ifPresent():

Optional<String> optionalName = transactionsList.stream()
    .filter(transaction -> transaction.getPayerIban() != null)
    .findFirst()
    .map(Transaction::getName);
Sign up to request clarification or add additional context in comments.

1 Comment

(From one Andy T to another...)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.