import java.util.ArrayList;
public class permutation {
public static ArrayList perm(String str)
{
if(str.length()==0)
{
ArrayList base=new ArrayList();
base.add("");
return base;
}
char c=str.charAt(0);
String cs=str.substring(1);
ArrayList result=new ArrayList<>();
ArrayList rr=perm(cs);
for(String ss : rr)
{
for(int i=0;i<ss.length();i++)
{
result.add(ss.substring(0,i)+cs+ss.substring(i));
}
}
return result;
}
public static void main(String[] args) {
System.out.println(perm(“abc”));
}
}