code: public static String trimWhitespace(final String s) {
          if (s == null || s.length() == 0) {
              return s;
          }
          final int length = s.length();
          int end = length;
          int start = 0;
  
          while (start < end && Character.isWhitespace(s.charAt(start))) {
              start++;
          }
          while (start < end && Character.isWhitespace(s.charAt(end - 1))) {
              end--;
          }
          return start > 0 || end < length ? s.substring(start, end) : s;
      }
docs: Strip leading and trailing whitespace from a String.
  
  Spring's version of StringUtils.trimWhitespace needlessly creates a StringBuilder when
  whitespace characters are not present, and java.lang.String.trim() removes non-printable
  characters in a non-unicode safe way.
  
  @param s
  string to be trimmed
  @return input string with leading and trailing whitespace removed.