全排列
package com.tianjunwei.rpc; import java.util.ArrayList; import java.util.Arrays; import java.util.List; /** * 全排列 */ public class A { public static void main(String[] args) { Integer a[] = {1, 2, 3, 4 ,5}; List<Integer> b = new ArrayList<>(); List c = new ArrayList<>(Arrays.asList(a)); print(c , b ); } public static void print(List<Integer> a ,List<Integer> b) { if(b.size() == a.size()) { for(int k = 0; k < b.size() ; k++) { System.out.print(b.get(k) + " "); } System.out.println(); return ; } int len = a.size(); for(int i = 0 ; i < len ; i++) { Integer ele = a.get(i); if(b.contains(ele)) { continue; } b.add(ele); print(a , b); b.remove(b.size() - 1); } } }