I have the following collection type:
Map> map;
I would like to create unique combinations of each o
Cartesian product in Java 8 with forEach:
List listA = new ArrayList<>();
listA.add("0");
listA.add("1");
List listB = new ArrayList<>();
listB.add("a");
listB.add("b");
List cartesianProduct = new ArrayList<>();
listA.forEach(a -> listB.forEach(b -> cartesianProduct.add(a + b)));
cartesianProduct.forEach(System.out::println);
//Output : 0a 0b 1a 1b