import java.util.ArrayList; public class PermuteInt { public static ArrayList> permutations(ArrayList list) { ArrayList> permuted_list = new ArrayList>(); if(list.size() < 2) { permuted_list.add(list); return permuted_list; } for(int i=0;i shorter_list = new ArrayList(); for(int j=0;j ilist : permutations(shorter_list)) { // Add back the element we took out to // make the shorter list the right length ilist.add(list.get(i)); // add the list to the list of permuted lists permuted_list.add(ilist); } } return permuted_list; } public static void main(String[] args) { ArrayList list = new ArrayList(); for(int i : new int[]{1,2,3,4}) { list.add(i); } for(ArrayList permuted_list : permutations(list)) { System.out.println(permuted_list); } } }