public boolean wordBreak(String s, Set<String> wordDict) {
boolean[] f = new boolean[s.length() + 1];
f[0] = true;
for (int i = 1; i <= s.length(); i++) {
for (int j = 0; j < i; j++) {
f[i] = f[j] && wordDict.contains(s.substring(j, i));
}
}
return f[s.length()];
}
6 line java solution

Good solution. Adding comments:
f[i]
keeps track of whether a substring from[0 to i)
satisfies wordBreak given the current dictionary.f[0]
is the empty string and the empty string satisfies wordBreak.This statement,
f[j] && wordDict.contains(s.substring(j, i))
, checks whethersubstring A
ANDsubstring B
satisfies wordBreak.
i
is the variable that is the current index for splittings
. 
j
is the variable that creates two substrings: fromsubstring A: [0 to j)
andsubstring B: [j to i)
ofs
.
f[i] = ...
uses the inclusive or. If true, then that means that there are at least two substrings, from[0 to j)
and[j to i)
ins
that satisfy wordBreak.Hope that helps!
