Similar to this problem but not sure how to create the algorithm in java.
I have an ArrayList<char[]> preCombination= [['a'],['b','B'],['c','C']]
How do I get an output ArrayList with =[['a','b','c'],['a','b','C'],['a','B','c'],['a','B','C']
I have tried to modify this permutation code into a combination one, however, I am unable to get into the inner loop. Appreciate if explanations is simple as I am new to coding, thanks in advance!
public static void permute(ArrayList <char[]> array,int index) {
if (index==array.size()-1) {
//System.out.println(array);
}
for (int i=index;i<array.size();i++) {
swap(array,i,index);
permute(array,index+1);
swap(array,i,index);
}
}
private static void swap(ArrayList <char[]> input,int a,int b) {
char[] temp=input.get(a);
input.set(a, input.get(b));
input.set(b, temp);
}