public static void main(String[] args) {
String ss="abc";
System.out.println(getpermutation(ss));
}
public static ArrayList getpermutation(String str){
StringBuilder sb=new StringBuilder(str);
if(str.length()==0){
ArrayList<String> base=new ArrayList<String>();
base.add(" ");
return base;
}
char cc=str.charAt(0);
String ros=str.substring(1);
ArrayList<String> recResult=getpermutation(ros);
ArrayList<StringBuilder> myResult=new ArrayList<StringBuilder>();
for(int i=0;i<recResult.size();i++) {
for(int j=0;j<=recResult.get(j).length();j++) {
myResult.add(sb.insert(j,cc));
}
}
return myResult;
}
}
// I am getting a type mismatch error at the last
.
and it is because of my return type is of ArrayList string Type and I am returning a Arraylist of StringBuilder.
Is there any way to convert ArrayList of StringBuilder to String without changing the return type of my function.