Java tutorial
//package com.java2s; import java.util.List; import java.util.Vector; public class Main { public static List<String> getAllPermutations(String s) { return getAllPermutations("", s); } private static List<String> getAllPermutations(String base, String toPermute) { List<String> permutations = new Vector<String>(); if (toPermute.length() == 1) { permutations.add(base + toPermute); return permutations; } //permuatations for (int i = 0; i < toPermute.length(); i++) { char a = toPermute.charAt(i); StringBuffer stillToPermute = (new StringBuffer(toPermute)).delete(i, i + 1); List<String> smallerPermuatations = getAllPermutations(base + a, new String(stillToPermute)); permutations.addAll(smallerPermuatations); } return permutations; } }