Here you can find the source of permutationBuilder2(ArrayList
public static ArrayList<ArrayList<Integer>> permutationBuilder2(ArrayList<ArrayList<Integer>> inputArray, int k)
//package com.java2s; //License from project: MIT License import java.util.ArrayList; public class Main { public static ArrayList<ArrayList<Integer>> permutationBuilder2(ArrayList<ArrayList<Integer>> inputArray, int k) { ArrayList<ArrayList<Integer>> listOfAllPerm = new ArrayList<ArrayList<Integer>>(); for (int i = 0; i < inputArray.size(); i++) { ArrayList<ArrayList<Integer>> listOfNewPerm = permutationBuilder(inputArray.get(i), k); for (int j = 0; j < listOfNewPerm.size(); j++) { listOfAllPerm.add(listOfNewPerm.get(j)); }//from w w w . jav a2s . co m } return listOfAllPerm; } public static ArrayList<ArrayList<Integer>> permutationBuilder(ArrayList<Integer> curList, int next) { ArrayList<ArrayList<Integer>> listOfNewPerm = new ArrayList<ArrayList<Integer>>(); for (int i = 0; i <= curList.size(); i++) { ArrayList<Integer> k = new ArrayList<Integer>(curList); k.add(i, next); listOfNewPerm.add(k); } return listOfNewPerm; } }