Create only 1 list from a map where map value is list using JAVA 8 Streams -


i have map, "value" list of projects:

map<user, list<project>> projectsmap = ... 

i want extract map projects in , 1 list of projects:

i've seen answers don't apply case. don't want result:

list<list<project>> thevalueofthemap; 

the result want is:

list<project> projects = ... // project in value's map 

how can achieve using java 8 streams? thanks. leonardo.

thanks @holger answer.

list<project> projects = projectsmap.values().stream().flatmap(list::stream) .collect(‌​collectors.tolist())‌​; 

code avoid nullpointerexception in case collection in value map null:

projectsmap.values().stream().filter(objects::nonnull) .flatmap(list::stream).collect(collectors.tolist()); 

Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -