递归列出一个String串中所有字母的所有可能的排列

package com.java.examples.digui;

public class AllOrderOfString {

	public static void allOrder(String str){
		if(str != null && !str.trim().equals("")){
			permuteString("",str);
		}
	}
	private static void permuteString(String beginningString, String endingString) {
		if (endingString.length() == 1)
			System.out.println(beginningString + endingString);
		else
			for (int i = 0; i < endingString.length(); i++) {
				String newString = endingString.substring(0, i)
						+ endingString.substring(i + 1);
				permuteString(beginningString + endingString.charAt(i),
						newString);
			}
	}

	public static void main(String[] args) {
		AllOrderOfString.allOrder("han");
	}
}

你可能感兴趣的:(java)