code: public static String truncateTo(String string, int maxLength) {
          if (string.length() <= maxLength) {
              return string;
          }
          return string.substring(0, maxLength);
      }
docs: Ensure that the given string is no longer than the given max length, truncating it
  if necessary. If string.length() is &lt;= maxLength, the same string is returned.
  Otherwise, a substring of the first maxLength characters is returned.
  
  @param string       String to test.
  @param maxLength    Maximum length.
  @return             Same or truncated string as described above.