Map<String, Set<T> > to List in Java 8 -
so have class :
class user { public string name; public integer age; public user(string name, integer age) { this.name = name; this.age = age; } }
and map
:
map<string, set<integer>> map = new hashmap<>(); map.put("user", set.of(18, 19, 20, 21));
i want obtain list of 4 users here:
- name : "john" , age : 18
- name : "john" , age : 19
- ....
- ....
any ideas how can streams
in java 8 ?
list<user> users = map.entryset() .stream() .flatmap(e -> e.getvalue().stream().map(x -> new user(e.getkey(), x))) .collect(collectors.tolist());
set.of
java-9 btw
Comments
Post a Comment