public class Demo2 { public static void main(String[] args) { // TODO Auto-generated method stub get("","123456"); } public static void get(String arr,String str){ if(str.length()==1){ System.out.println(arr+str); }else{ for(int i=0;i<str.length();i++){ String temp = str.substring(i, i+1); String l=arr+temp; String a=str.replace(temp, ""); get(l,a); } } } }