Reputation: 119
I have a HashMap like below
{ HHsize=[HHSize4+, HHSize1, HHSize2, HHSize3],
AOB=[AOB<30, AOB30_50, AOB60Plus, AOB50_60],
Asp=[Asp=N, Asp=Y]}
I need to generate all possible combinations of the value pairs. As a Cartesian product For example.
[[HHSize4+,AOB<30,Asp=N],
[HHSize4+,AOB<30,Asp=Y],
[HHSize4+,AOB30_50,Asp=N],
[HHSize4+,AOB30_50,Asp=Y],
and so on.
How can we go about this?
Upvotes: 0
Views: 881
Reputation: 53849
Using Guava Sets
:
List<Set<String>> values = map.values()
.stream()
.map(HashSet::new) // to set
.collect(Collectors.toList());
Set<List<String>> = Sets.cartesianProduct(values);
Upvotes: 1