import java.util.ArrayList;
import java.util.Arrays;
public class ArraySort{
public static void main(String[] args){
String[] strs = {"A","B","C","D"};
ArrayList<String[]> list = ArraySort.arraySort(strs);
for(int i = 0;i < list.size();i ++){
strs = list.get(i);
ArraySort.print(strs);
}
}
public static <E> ArrayList<E[]> arraySort(E[] array){
ArrayList<E[]> list = new ArrayList<E[]>();
arraySort(array,0,list);
return list;
}
private static <E> void arraySort(E[] array,int index,ArrayList<E[]> list){
if(index < 0 || index > array.length){
System.err.println("Unkown Parameter of index:" + index + "!");
System.exit(1);
}
if(index == array.length){
list.add(Arrays.copyOfRange(array,0,index));
}
E temp = null;
for(int i = index ; i < array.length ; i ++){
temp = array[i];
array[i] = array[index];
array[index] = temp;
arraySort(array,index + 1,list);
temp = array[i];
array[i] = array[index];
array[index] = temp;
}
}
private static <E> void print(E[] eArray){
for(E e : eArray){
System.out.print(e);
}
System.out.println();
}
}