public static <T> String extractNgram(List<T> list, int start, int end) {
    if (start < 0 || end > list.size() || start >= end) return null;
    final StringBuilder sb = new StringBuilder();
    // TODO: iterator
    for (int i = start; i < end; i++) {
      T o = list.get(i);
      if (sb.length() != 0) sb.append(" ");
      sb.append((o instanceof HasWord) ? ((HasWord) o).word() : o.toString());
    }
    return sb.toString();
  }
public static < T > String extractNgram ( List < T > list , int start , int end ) { if ( start < 0 || end > list . size ( ) || start >= end ) return null ; final StringBuilder sb = new StringBuilder ( ) ; for ( int i = start ; i < end ; i ++ ) { T o = list . get ( i ) ; if ( sb . length ( ) != 0 ) sb . append ( " " ) ; sb . append ( ( o instanceof HasWord ) ? ( ( HasWord ) o ) . word ( ) : o . toString ( ) ) ; } return sb . toString ( ) ; }
Returns the substring of the sentence from start (inclusive)
to end (exclusive).

@param start Leftmost index of the substring
@param end Rightmost index of the ngram
@return The ngram as a String