0

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 );
            }

        }
    }
}
  • This is a question about combinations. Why has it been marked as a duplicate of a question about permutations? – NorthernSky Aug 27 '19 at 13:43
  • I think the solution could involve generating all subsets and then using the answer at [Generating all permutations of a given string](https://stackoverflow.com/questions/4240080/generating-all-permutations-of-a-given-string) to generate all permutations of each subset. Voting to reopen, since the combination problem is indeed not solved by the permutations answer. – joanis Aug 27 '19 at 15:22

0 Answers0