
public static List descartes(List... lists) {
List tempList = new ArrayList<>();
for (List list : lists) {
if (tempList.isEmpty()) {
tempList = list;
} else {
//java8新特性,stream流
tempList = tempList.stream().flatMap(item -> list.stream().map(item2 -> item + " " + item2)).collect(Collectors.toList());
}
}
return tempList;
}
test
public static void main(String[] args) {
List colorList = Arrays.asList("红色", "黑色", "金色");
List sizeList = Arrays.asList("32G", "64G");
List placeList = Arrays.asList("国产", "进口");
List descartesList = descartes(colorList, sizeList, placeList);
descartesList.forEach(System.out::println);
}
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)