import java.util.ArrayList; public class Day08 { // Generates all permutations of characters in str public static ArrayList allPermutations( String str ) { ArrayList result = new ArrayList( ); if( str.equals( "" ) ) result.add( "" ); else { for( int i = 0; i < str.length( ); i++ ) { // (for each character in str) char thisChar = str.charAt( i ); String smallString = str.substring( 0, i ) + str.substring( i + 1 ); for( String s : allPermutations( smallString ) ) result.add( thisChar + s ); } } return result; } public static void main( String [ ] args ) { ArrayList perms = allPermutations( "abcde" ); System.out.println( perms.size( ) ); System.out.println( perms ); } }