Sunil Kumar
Sunil Kumar

Reputation: 1359

Why Map function not works in nested stream

Hi In the below code map function wont run but for each run

List<ValidationError> validationErrors = validationErrorResponse.getValidationErrors();
validationErrors.stream().forEach(validationError -> {
    System.out.println("Hello1"+validationError.getProperty());
    System.out.println("Hello1"+validationError.getErrors().toString());
    List<String> errors = validationError.getErrors();
            errors.stream().map(x-> ErrorCode.valueOf(x));

Upvotes: 0

Views: 87

Answers (1)

k5_
k5_

Reputation: 5568

map is an intermediate operation on stream. So it will executed iff you add a terminal operation, like collect or forEach to it.

So something like:

errors.stream().map(x-> ErrorCode.valueOf(x)).forEach( x -> System.out.println(x) );

Upvotes: 2

Related Questions