現在、関数から返すArrayListをメイン関数の新しいArrayListに必死に取得しようとしています...
コード スニペットは次のとおりです。
public static ArrayList<String> permute(String begin, String end) {
ArrayList<String> al=new ArrayList<String>();
//filling bla
return al;
}
メイン関数で関数を呼び出す場所は次のとおりです。
ArrayList<String> arr =permute("","abc");
残念ながら arr は空で、それを機能させる方法がわかりません:(
前もって感謝します
編集:完全なコードは次のとおりです。
import java.util.*;
class Problem24 {
public static ArrayList<String> permute(String begin, String end) {
ArrayList<String> al=new ArrayList<String>();
if (end.length() <= 1) {
String s=begin+end;
al.add(s);
} else {
for (int i = 0; i < end.length(); i++) {
try {
String newString = end.substring(0, i) + end.substring(i + 1);
permute(begin + end.charAt(i), newString);
} catch (StringIndexOutOfBoundsException exception) {
exception.printStackTrace();
}
}
}
return al;
}
public static void main (String[] args)
{
ArrayList<String> arr =permute("","abc");
System.out.println(arr.get(0));
}
}