iterator - Joining (union) of Sets inside a Set in Java -


i have map values sets of integers. i'd want in best way possible (using java api great) union of sets of integers.

map<long, set<integer>> map; 

what thought far loop through values() of map , manually add big set:

set<integer> bigset = new hashset<>(); iterator<set<integer>> iter = map.values().iterator(); while(iter.hasnext())     bigset.addall(iter.next()); 

also collection union backed map great. unfortunately stuck java 7.

on 1 hand use new java 8 fluent interface

import static java.util.stream.collectors.toset;  set<integer> myunion = map         .values()         .stream()         .flatmap(set -> set.stream())         .collect(toset()); 

on other hand suggest taking @ guava's setmultimap if can use external libraries.


Comments

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -