I need to create 2 lists based on a predicate by using stream().reduce(). I got a similar code but it's not working.
localRequestDTOList.stream().reduce((res, item) ->{
res[predicate(item) ? 'a' : 'b'].push(item);
return res;
}, { a: [], b: [] });
The predicate is shown below.
public static Predicate<LocalRequestDTO> payToVendor() {
return request -> (request.getSuffix().equals("00"));
}
What I want is from localRequestDTOList create two lists with the condition that their request.getsuffix().equals("00")
or not. I simply put the two lists as a
and b
.