Code not working for stings greater than 3

// exception-java.lang.StringIndexOutOfBoundsException
import java.util.ArrayList;

public class permutations {

public static void main(String[] args) {
	// TODO Auto-generated method stub
	System.out.println(permutation("abcd"));
}

private static ArrayList<String> permutation(String str) {
	// TODO Auto-generated method stub
	if(str.length()==0) {
		ArrayList<String> base=new ArrayList();
		base.add("");
		return base;
	}
	char cc=str.charAt(0);
	String rest=str.substring(1);
	ArrayList<String> rec=permutation(rest);
	ArrayList<String> result=new ArrayList();
	for(int i=0;i<rec.size();i++) {
		String travel=rec.get(i);
		for(int j=0;j<=travel.length();j++) {
			String finalstr=travel.substring(0,i)+cc+travel.substring(i);
			result.add(finalstr);
		}
	}
	return result;
}

}

@javadsalgo123
String finalstr=travel.substring(0,j)+cc+travel.substring(j)

j instead of i here