Is there a way to get all possible combinations of the letters of a given string? I don't want to ignore doubled letters. Also I want to get all possibilitys, even if not every letter is used. For example: String is ABCDE, so i also want to see the combinations of BCDE, ACDE, ABDE, ABCE, ABCD
I already tried the code found here, but I think not every combination is included.
public class Main {
private StringBuilder output = new StringBuilder();
private final String inputstring;
public Main( final String str ){
inputstring = str;
System.out.println("The input string is : " + inputstring);
}
public static void main(String[] args) {
Main main= new Main("VRIDENNBEN");
System.out.println("All possible combinations are : ");
main.combine();
}
public void combine() {
combine( 0 );
}
private void combine(int start ){
for( int i = start; i < inputstring.length(); ++i ){
output.append( inputstring.charAt(i) );
if(true) {
System.out.println( output );
if ( i < inputstring.length() )
combine( i + 1);
output.setLength( output.length() - 1 );
}
}
}
}