更新时间:2022-11-09 12:31:04
迭代两个数组,并在每个步骤上创建新的字符串组合.毕竟只是以某种方式打印组合.
Iterate over two arrays and on each step make new string combination. After all just print combinations in some way.
List<String[]> input = ...;
Set<String> allCombinations = new HashSet<>();
for (int i = 0; i < input.size() - 1; i++) {
for (int j = i + 1; j < input.size(); j++) {
allCombinations.addAll(twoArraysCombinations(input.get(i), input.get(j)));
}
}
// print allCombinations
private static Set<String> twoArraysCombinations(String[] first, String[] second) {
Set<String> result = new HashSet<>();
for (String f : first) {
for (String s : second) {
result.add(f + s);
}
}
return result;
}