Wed Apr 19 07:38:40 UTC 2023 inscode

上级 5b0ce43e
class Main { import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static java.util.stream.Collectors.toList;
public class Main {
public static void main(String[] args) { public static void main(String[] args) {
System.out.println("Hello world!"); List<String> list1 = Arrays.asList("A", "B", "C");
List<String> list2 = Arrays.asList("1", "2");
List<String> result = product(list1, list2);
result.forEach(System.out::println);
}
/**
* @param lists 可变长度参数列表
* */
public static List<String> product(List<String>... lists) {
List<String> temp = new ArrayList<>();
for (List<String> list : lists) {
if (temp.isEmpty()) {
temp = list;
} else {
// stream流 flatMap 和 map 方法
temp = temp.stream().flatMap(o1 -> list.stream().map(o2 -> o1 + " " + o2)).collect(toList());
}
}
return temp;
} }
} }
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册