code: public static String prettyPrint(String in, int lineLength, String delim) {
          // make a guess about resulting length to minimize copying
          StringBuilder sb = new StringBuilder(in.length() + in.length()/lineLength);
          if (delim == null) {
              delim = " ";
          }
          StringTokenizer st = new StringTokenizer(in, delim);
          int charCount = 0;
          while (st.hasMoreTokens()) {
              String s = st.nextToken();
              charCount = charCount + s.length();
              if (charCount < lineLength) {
                  sb.append(s);
                  sb.append(' ');
                  charCount++;
              } else {
                  sb.append('\n');
                  sb.append(s);
                  sb.append(' ');
                  charCount = s.length() + 1;
              }
          }
          return sb.toString();
      }
docs: Method that attempts to break a string up into lines no longer than the
  specified line length.
  
  <p>The string is assumed to consist of tokens separated by a delimeter.
  The default delimiter is a space. If the last token to be added to a
  line exceeds the specified line length, it is written on the next line
  so actual line length is approximate given the specified line length
  and the length of tokens in the string.
  
  @param in
  The input string to be split into lines.
  @param lineLength
  The maximum length of each line.
  @param delim
  The character delimiter separating each token in the input string;
  if null, defaults to the space character.
  @return A string split into multiple lines whose length is less than the
  specified length. Actual length is approximate depending on line
  length, token size, and how many complete tokens will fit into
  the specified line length.