Imaging object with following method:
class A { List<B> getIds(){...} }
Now I have an Collection of A as input; And I want to get set of unique Ids out of it, normally you would go for:
Set<B> ids = new HashSet<>();
for(A a : input){
ids.addAll(a.getIds());
}
Is there a way to do the same in one line using stream API, like following
Set<List<B>> set = input.stream().map((a) -> a.getIds()).collect(Collectors.toSet());
but making flat set of B