Find meaningful words from the input string Given a string find the number of meaningful words which could be formed from the string 
for eg. programmerit forms:


pro+gram+merit
program+merit
programmer+it
pro+grammer+it



Looking for code review optimizations and best practices. Also hoping for suggestions for complexity better than \$O(n^2)\$, where n is the number of characters.

public final class DictionaryValidWords {

    private static final Set&lt;String&gt; dictionary = new TreeSet&lt;String&gt;();
    static {
        dictionary.add("this");
        dictionary.add("his");
        dictionary.add("is");
        dictionary.add("awe");
        dictionary.add("we");
        dictionary.add("some");
        dictionary.add("awesome");
        dictionary.add("foo");
        dictionary.add("bar");
    }

    private DictionaryValidWords() {}

    /**
     * Returns set of valid words given an input string.
     * It eliminates duplicates.
     * 
     * @param str   The input string whose valid words need to be found out.
     * @return      List of valid words nested in the string.
     */
    public static Set&lt;String&gt; findValidStrings(String str) {
        if (str.length() ==  0) {
            throw new IllegalArgumentException("Strings of length 0 are illegal");
        }

        final Set&lt;String&gt; validWords = new HashSet&lt;String&gt;(); 
        for (int i = 0; i &lt; str.length(); i++) {
            StringBuilder sb = new StringBuilder();
            for (int j = i; j &lt; str.length(); j++) {
                sb.append(str.charAt(j)); // O(1) complexity.
                if (dictionary.contains(sb.toString())) {
                    validWords.add(sb.toString());
                }
            }
        }
        return validWords;
    }
}



public class DictionartValidWordTest {

    @Test
    public void testValidWords() {
        Set&lt;String&gt; expectedSet = new HashSet&lt;String&gt;(Arrays.asList("awe", "is", "his", "awesome", "some", "this", "we"));
        assertEquals(expectedSet, DictionaryValidWords.findValidStrings("thisisawesome"));
    }
}
I only have one minor objection for the moment...
...
...
Why are you not using dependency injection??
OK, it turned out to be a major one. (I did consider using caps-lock!)
Consider a situation where you would want to do this operation for English words, and then for French words. Instead of using all things static, make a public constructor
private final Set&lt;String&gt; dictionary;

public DictionaryValidWords(Set&lt;String&gt; dictionary) {
    this.dictionary = dictionary;
}

You might consider this as &quot;outside the core part of the code&quot; but it's really not. And it is a very important change to make, class-design wise and best-practices wise.
You could then use a DictionaryFactory class where you could have methods (static or non-static, as you prefer), for exampleDictionary (your current dictionary), english, french, etc...