List集合中有多个List集合,每个集合中存储多个字符串,每次从每个集合里面取出一个元素组成一个字符串
使用递归实现
下面直接上代码:
public class Test {
public static void main(String[] args) {
List<List<String>> strings = new ArrayList<>();
strings.add(new ArrayList(Arrays.asList("1", "2", "3")));
strings.add(new ArrayList(Arrays.asList("a", "b", "c")));
strings.add(new ArrayList(Arrays.asList("x", "y", "z")));
List<String> list = test(strings, strings.get(0), "", new ArrayList<>());
System.out.println(list);
}
public static List<String> test(List<List<String>> list, List<String> arr, String str, List<String> result) {
for (int i = 0; i < list.size(); i++) {
//取得当前的集合
if (i == list.indexOf(arr)) {