Permutations using Arraylist

I'm having problem with not outputting the correct result. I only get the original permutation back. It doesn't want to iterate through the rest of the letters.

Question is, I'm following the string implementation of finding permutations but I've edited it using arraylist. Now since Strings are immutable, is that the cause of my problem when using Arraylist?

Code :

public BinaryTree optimize2() {
ArrayList<String> growing = new ArrayList();
optimize(growing, this.keys);
return null;
}
public static void optimize2(ArrayList<String> growing, ArrayList<String> remaining){
//System.out.println(growing);
//System.out.println(remaining);
if(remaining.size() == 0) System.out.println("base" +growing);
else{
//remaining.remove(0);
//optimize(growing,remaining);
for(int i = 0 ; i < remaining.size(); i++){
growing.add(remaining.get(i));
System.out.print("growing" + growing);
remaining.remove(remaining.indexOf(remaining.get(i)));
System.out.println("remaining" + remaining);
optimize2( growing, remaining );
}
}
}

OUTPUT with A,B,C:

Quote:

growing[A]remaining[B, C]

growing[A, B]remaining[C]

growing[A, B, C]remaining[]

base[A, B, C]

Thanks

Re: Permutations using Arraylist

Duplicate post and so closed.