Home > Back-end >  Use flatMap Stream flow
Use flatMap Stream flow

Time:09-29

There is a List List collection now use flatMap in Steam flow to obtain without the Map key values and then flattening finally get a collection has all the key value is Set inside the Map

CodePudding user response:

Didn't get access to without the Map key value is what you mean
If you want to get all the inside of the Map of all the key, can the following
List Keys=list. Stream (). FlatMap (m - & gt; M.k eySet (). The stream ()). Collect (Collectors. ToList ());
If you don't repeat the key, which can be the following
Set Keys=list. Stream (). FlatMap (m - & gt; M.k eySet (). The stream ()). Collect (Collectors. ToSet ());

CodePudding user response:

Set AllKey=list. Stream (). The map (the map: : keySet). FlatMap (Collection: : stream). Collect (Collectors. ToSet ());

CodePudding user response:

reference 1st floor qybao response:
didn't get get no Map key value is what you mean
If you want to get all the inside of the Map of all the key, can the following
List Keys=list. Stream (). FlatMap (m - & gt; M.k eySet (). The stream ()). Collect (Collectors. ToList ());
If you don't repeat the key, which can be the following
Set Keys=list. Stream (). FlatMap (m - & gt; M.k eySet (). The stream ()). Collect (Collectors. ToSet ());
thank you very much

CodePudding user response:

refer to the second floor kse_music response:
Set AllKey=list. Stream (). The map (the map: : keySet). FlatMap (Collection: : stream). Collect (Collectors. ToSet ());
thank you very much
  • Related