Get all combinations of Strings
<p>I have requirement that need to get all combinations of given Strings.
For example 
I have a String of digits and some special charcters</p>

<pre><code>String chars="0123456789@#$%&amp;";
String guessedPw="authentic";
</code></pre>

<p>So I want to get combinations like this</p>

<ol>
<li>$authentic%4 </li>
<li>authentic#@ </li>
<li>5&amp;authentic</li>
<li>authentic8</li>
</ol>

<p>How should I improve my method to get all combinations?</p>

<p>This is the code that I have written.</p>

<p>but it doesn't give me all combinations.</p>

<pre><code>private static String combination(String prefix, String s, String pw, String md5Pw) {
    String pwFound = "";
    if (s.length() &gt; 0) {
        // System.out.println(prefix + s.charAt(0) + pw);

        String tempPw1 = prefix + s.charAt(0) + pw;
        System.out.println("pw1 : " + tempPw1);
        if (md5(tempPw1).equals(md5Pw)) {
            // String tempPw1;
            pwFound = tempPw1;

            return pwFound;

        }

        String tempPw2 = pw + prefix + s.charAt(0);


        if (md5(tempPw2).equals(md5Pw)) {
            // String tempPw1;
            pwFound = tempPw2;
            return pwFound;

        }

        pwFound = combination(prefix + s.charAt(0), s.substring(1), pw, md5Pw);
        pwFound = combination(prefix, s.substring(1), pw, md5Pw);
    }
    return pwFound;
}
</code></pre>