Q:

How do I get not just all substrings, but all POSSIBLE substrings of a string? 

I have the following code : 
public class Application {

public static void main(String[] args)
{
    String source = "Testing";
    go(source);
}

public static void go(String source)
{
    for (int i = 0; i < source.length(); i ++)
    {
        for (int j = i + 1; j <= source.length(); j++)
        {
            System.out.println(source.substring(i, j));
        }
    }
}

}
When I run this code, I get the following output : 
T
Te
Tes
Test
Testi
Testin
Testing
e
es
est
esti
estin
esting
s
st
sti
stin
sting
t
ti
tin
ting
i
in
ing
n
ng
g

Which is great and all - But it isn't actually what I want.  I would also like to be able to get all the possible strings that are substrings of this word. 
Such as gist, set, tie etc. 
I realise how my code is wrong for this, but I am also unsure of how I might expand it out to achieve what I want! 
Any help is appreciated! 

A:

By having this permutations function (taken from Generating all permutations of a given string):
public static List<String> permutation(final String str) {
    return permutation("", str);
}

private static List<String> permutation(final String prefix, final String str) {
    final List<String> list = new ArrayList<>();

    final int n = str.length();
    if (n == 0) {
        list.add(prefix);
    } else {
        for (int i = 0; i < n; i++) {
            list.addAll(permutation(prefix + str.charAt(i),
                                    str.substring(0, i) + str.substring(i + 1, n)));
        }
    }

    return list;
}

And this substring function (just changed the return type of your function):
public static List<String> substrings(final String source) {
    final List<String> list = new ArrayList<>();
    for (int i = 0; i < source.length(); i++) {
        for (int j = i + 1; j <= source.length(); j++) {
            list.add(source.substring(i, j));
        }
    }
    return list;
}

I made this solution using Java 8 streams:
public static void main(String[] args) {
    Stream.of("Testing")
          .flatMap(s -> permutation(s).stream())
          .flatMap(s -> substrings(s).stream())
          .distinct()
          .forEach(System.out::println);
}

