title: Large string split into lines with maximum length in java
body: <pre><code>String input = "THESE TERMS AND CONDITIONS OF SERVICE (the Terms) ARE A LEGAL AND BINDING AGREEMENT BETWEEN YOU AND NATIONAL GEOGRAPHIC governing your use of this site, www.nationalgeographic.com, which includes but is not limited to products, software and services offered by way of the website such as the Video Player, Uploader, and other applications that link to these Terms (the Site). Please review the Terms fully before you continue to use the Site. By using the Site, you agree to be bound by the Terms. You shall also be subject to any additional terms posted with respect to individual sections of the Site. Please review our Privacy Policy, which also governs your use of the Site, to understand our practices. If you do not agree, please discontinue using the Site. National Geographic reserves the right to change the Terms at any time without prior notice. Your continued access or use of the Site after such changes indicates your acceptance of the Terms as modified. It is your responsibility to review the Terms regularly. The Terms were last updated on 18 July 2011.";
  
  //text copied from http://www.nationalgeographic.com/community/terms/
  </code></pre>
  
  <p>I want to split this large string into lines and the lines should not content more than MAX_LINE_LENGTH characters in each line. </p>
  
  <p><strong>What I tried so far</strong></p>
  
  <pre><code>int MAX_LINE_LENGTH = 20;    
  System.out.print(Arrays.toString(input.split("(?&lt;=\\G.{MAX_LINE_LENGTH})")));
  //maximum length of line 20 characters
  </code></pre>
  
  <p><strong>Output :</strong></p>
  
  <pre><code>[THESE TERMS AND COND, ITIONS OF SERVICE (t, he Terms) ARE A LEGA, L AND B ...
  </code></pre>
  
  <p>It causes <strong>breaking of words</strong>. I don't want this.
  Instead of I want to get output like this:</p>
  
  <pre><code>[THESE TERMS AND , CONDITIONS OF , SERVICE (the Terms) , ARE A LEGAL AND B ...
  </code></pre>
  
  <p><strong>One more condition added :</strong>
  If a word length is greater than MAX_LINE_LENGTH then the word should get split.</p>
  
  <p>And solution should be without helping of external jars.</p>