I am trying to do permutations in java of a String given an Integer Number.
So if the String is "abc" and the Integer Number is 2.
I want the following results:
ab ac ba bc ca cb
If the String is also "abc" but the Integer Number is 3, I want the following results:
abc bac cba bca cab acb
I have already the following method:
private static void permutation(String prefix, String str) {
int n = str.length();
if (n == 0) permutationsList.add(prefix);
else {
for (int i = 0; i < n; i++)
permutation(prefix + str.charAt(i), str.substring(0, i) + str.substring(i+1, n));
}
}
But this only works for the Integer Number equals to the String size, in this case 3.
So can something help me to make this work, with a Integer argument?
Thanks alot in advance ;)