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

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

posted @ 2015-07-16 09:22  chuiyuan  阅读(678)  评论(0编辑  收藏  举报