Here you can find the source of getPermutationsRec(List
private static void getPermutationsRec(List<byte[]> permutations, byte[] order, List<Stack<Byte>> remaining, int index)
//package com.java2s; //License from project: Open Source License import java.util.List; import java.util.Stack; public class Main { private static void getPermutationsRec(List<byte[]> permutations, byte[] order, List<Stack<Byte>> remaining, int index) { if (order[order.length - 1] != 0) { permutations.add(order.clone()); }/*from ww w. j a v a2 s . c om*/ for (Stack<Byte> stack : remaining) { if (stack.empty()) { // nothing } else { order[index] = stack.pop(); getPermutationsRec(permutations, order, remaining, index + 1); stack.push(order[index]); order[index] = 0; } } } }