code: public static String truncate(String str, int count)
      {
          if(count < 0 || str.length() <= count)
              return str;
  
          int pos = count;
          for(int i = count; i >= 0 && !Character.isWhitespace(str.charAt(i)); i--, pos--);
          return str.substring(0, pos)+"...";
      }
docs: Returns the given string truncated at a word break before the given number of characters.
  @param str The string to be truncated
  @param count The maximum length of the truncated string
  @return The truncated string