This article illustrates the method of implementing the whole array of character arrays in Java. Share to everyone for your reference, specific as follows:
Import Org.junit.Test;
public class Allsort {public
void permutation (char[] buf, int start, int end) {
if (start = = end) {//When only one word in an array is required When the parent is in full arrangement, just press the array output for
(int i = 0; I <= end; i++) {
System.out.print (buf[i]);
}
System.out.println ();
} else {//Multiple letters for
(int i = start; I <= end; i++) {
Char temp = buf[start];//Exchange array The first element and subsequent elements
Buf[start ] = Buf[i];
Buf[i] = temp;
Permutation (buf, start + 1, end);/subsequent elements recursively all arranged
temp = buf[start];//Restore the swapped array
Buf[start] = buf[i];
Buf[i] = temp;
}
}} @Test public
void Testpermutation () throws Exception {
char[] buf = new char[] {' A ', ' B ', ' C '};
Permutation (buf, 0, 2);
}
}
Run the test and output the results:
Abc
Acb
Bac
Bca
Cba
Cab
I hope this article will help you with Java programming.