import java.util.ArrayList; import java.util.Collections; import java.util.List; public class ArrangedUtil { private static List<List<?>> allList = new ArrayList<>(); public static <T>void getAll(List<T> list,List<T> list2,int n){ for (T object : list2) { List<T> ll = new ArrayList<>(); ll.add(object); List<T> ll2 = new ArrayList<>(list2); ll2.remove(object); ll.addAll(list); getAll(ll,ll2,n); if(ll.size() == n){ allList.add(ll); } } } public static void main(String[] args) { List<Integer> data = new ArrayList<>(); Collections.addAll(data, 1,2,3); getAll(new ArrayList<Integer>(),data,data.size()); for (List<?> list: allList) { System.out.println(list); } } }
运行结果: