title: N-gram generation from a sentence
body: <p>How to generate an n-gram of a string like:</p>
  
  <pre><code>String Input="This is my car."
  </code></pre>
  
  <p>I want to generate n-gram with this input:</p>
  
  <pre><code>Input Ngram size = 3
  </code></pre>
  
  <p>Output should be:</p>
  
  <pre class="lang-none prettyprint-override"><code>This
  is
  my
  car
  
  This is
  is my
  my car
  
  This is my
  is my car
  </code></pre>
  
  <p>Give some idea in Java, how to implement that or if any library is available for it.</p>
  
  <p>I am trying to use <a href="http://lucene.apache.org/java/3_0_2/api/all/org/apache/lucene/analysis/ngram/NGramTokenizer.html" rel="noreferrer">this NGramTokenizer</a> but its giving n-gram's of character sequence and I want n-grams of word sequence.</p>