你需要递归:
假设你的所有列表都在中
lists,这是列表的列表。让
result是你所需要的排列的列表。你可以这样实现:
void generatePermutations(List<List<Character>> lists, List<String> result, int depth, String current) { if (depth == lists.size()) { result.add(current); return; } for (int i = 0; i < lists.get(depth).size(); i++) { generatePermutations(lists, result, depth + 1, current + lists.get(depth).get(i)); }}最终的呼叫将是这样的:
generatePermutations(lists, result, 0, "");



