code: public static String trimWhitespace(String str) {
          if (!hasLength(str)) {
              return str;
          }
          StringBuilder buf = new StringBuilder(str);
          while (buf.length() > 0 && Character.isWhitespace(buf.charAt(0))) {
              buf.deleteCharAt(0);
          }
          while (buf.length() > 0 && Character.isWhitespace(buf.charAt(buf.length() - 1))) {
              buf.deleteCharAt(buf.length() - 1);
          }
          return buf.toString();
      }
docs: Trim leading and trailing whitespace from the given {@code String}.
  
  @param str the {@code String} to check
  @return the trimmed {@code String}
  @see java.lang.Character#isWhitespace