I have an idList collection that contains row ids. The getCollection function returns a collection of elements (type MyType) for a single ID . In addition, it can return null.
So, for many identifiers from idList, I would get some null values ​​and some collections.
The goal is to collect all getCollection responses for a set of identifiers into a final list.
I imagined something like
List<MyType> reply = idList.stream().map(id -> getCollection(id)) .filter(p -> p != null).collect(Collectors.toList());
but this does not seem to be a valid expression. How to do it?
Also, how about doing this implementation?
source share