code: public static String trimTrailing(String str) {
          if (str == null) {
              return null;
          }
          int len = str.length();
          for (; len > 0; len--) {
              if (!Character.isWhitespace(str.charAt(len - 1))) {
                  break;
              }
          }
          return str.substring(0, len);
      }
docs: Trim off trailing blanks but not leading blanks
  @param str
  @return The input with trailing blanks stipped off