乐趣区

关于lambda:lambda-生成笛卡尔集

public static void getDiKaEr() {List<List<String>> source = new ArrayList<>();
 List<String> color = Arrays.asList("红色", "红色", "蓝色");
 List<String> size = Arrays.asList("中", "大", "小");
 List<String> origins = Arrays.asList("中国", "瑞士");
 source.add(color);
 source.add(size);
 source.add(origins);
 List<String> result = source.stream().reduce((a, b) -> {List<String> results = new ArrayList<>();
 a.forEach(param1 -> {
            b.forEach(param2 -> {results.add(param1 + "-" + param2);
 });
 });
 return results;
 }).get();
 System.out.println(result);
}
退出移动版