I have a collection that has a field of type Set with some values. I need to create a new set that collects all these values.
I am wondering if this is possible with lambda expressions.
The following is a line of code:
Set<String> teacherId = batches.stream()
.filter(b -> !CollectionUtils.isEmpty(b.getTeacherIds()))
.map(b -> b.getTeacherIds())
.collect(Collectors.toSet());
The problem is the post map operation, it contains a set of rows. Thus, the collection operation returns a Set<Set<String>>, but I want to aggregate all the values ββinto a single set.
source
share