将一个数组里面的组合全部列出

public class Test {
	
	public static void main(String [] args){
		String[]  array =new String[] {"1","2","3"};
		listAll(Arrays.asList(array), "") ;
	}
	public static void listAll(List canditate,String prefix){
		System.out.println(prefix) ;
		for (int i=0;i<canditate.size();i++){
			List temp = new LinkedList(canditate);
			listAll(temp, prefix+ temp.remove(i)) ;
		}
	}
	
}

结果为

 


1
12
123
13
132
2
21
213
23
231
3
31
312
32
321

原文地址:https://www.cnblogs.com/chuiyuan/p/4650261.html