Reputation: 1001
I am trying to access a list of string from a data structure which is having collection of collection. What I have tried yet is returning a list of collection,but I want a single list. Here is my code:
Collection result= (Collection)allPatientsAccessRecords.stream()
.filter(rec -> rec.data.personId==8191).map(data->data.accessData.associatedAreas).
collect(Collectors.toList());
Here is a snapshot of a source data structure:
Can someone hint me how i can get accessData->associatedArea(list of string) as a result using stream API ?
Upvotes: 1
Views: 97
Reputation: 1010
This should get you started:
List<List<String>> example = ... ;
example.stream().flatMap(list->list.stream()).collect(...)
Upvotes: 1
Reputation: 17890
Use flatMap
allPatientsAccessRecords.stream()
.filter(rec -> rec.data.personId == 8191)
.flatMap(data -> data.accessData.associatedAreas.stream())
.collect(Collectors.toList());
Upvotes: 3