Here you can find the source of permutationBuilder(ArrayList
public static ArrayList<ArrayList<Integer>> permutationBuilder(ArrayList<Integer> curList, int next)
//package com.java2s; //License from project: MIT License import java.util.ArrayList; public class Main { 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);/* w w w . ja va2s . c o m*/ listOfNewPerm.add(k); } return listOfNewPerm; } }