All combinations of a string with special characters
Well, you can simply find out where the * can be, e.g.:

___, __*, _**, _*_, **_, ***,*__


and then replace:

fin, fi*, f**, f*n, **n, ***,*in


Code:

public static String[] possibleCombinations(String s) {
    int length = s.length();
    char[][] strings = new char[length * (length + 1) / 2][length];
    for (int i = 0; i &lt; strings.length; i++) {
        strings[i] = s.toCharArray();
    }
    strings[0][0] = '*';
    for (int i = 0, j = 0, counter = 0; i &lt; length; i++, counter += length - i + 1, j = i) {
        for (; j &lt; length; j++) {
            for (int k = j; k &lt; length; k++) {
                strings[counter + k - i][j] = '*';
            }
        }
    }
    String[] result = new String[strings.length + 1];
    result[0] = s;
    for (int i = 0; i &lt; strings.length; i++) {
        result[i + 1] = new String(strings[i]);
    }
    return result;
}


It's fairly fast:


aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
*aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
**aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
***aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
...
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa***
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa*a
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa**
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa*
length: 50
Time taken: 1064956 nanoseconds






Length: 500
Time taken: 733033361 nanoseconds