I am using Java 8 stream
executeRequest(requestId).stream()
.map(d-> (Response) d).collect(Collectors.toList());
the Response object is like this
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class Response {
String title;
String id;
}
when the responses are null, I am getting an error because it is trying to collect null values in a list, I want to have a condition that when title is null, stream does not continue, or any thing that helps me to handle it
.filter(r -> r.title != null). for latter u might want to use.takeWhile(r -> r.title != null)or similar..filter(r -> r.title != null). carefully read the suggestions.