Pick start point in outer loop and lengths of different Strings for a given starting point
for ( int i = 0 ; i < n ; i ++ ) { for ( int len = 1 ; len <= n - i ; len ++ ) { String find = s . substring ( i , i + len ) ; v . add ( find ) ; } }