code: private static String trimEnd(String s) {
      int trimCount = 0;
      while (trimCount < s.length()) {
        char ch = s.charAt(s.length() - trimCount - 1);
        if (TokenUtil.isWhitespace(ch)) {
          trimCount++;
        } else {
          break;
        }
      }
  
      if (trimCount == 0) {
        return s;
      }
      return s.substring(0, s.length() - trimCount);
    }
docs: Trim characters from only the end of a string.
  This method will remove all whitespace characters
  (defined by TokenUtil.isWhitespace(char), in addition to the characters
  provided, from the end of the provided string.
  
  @param s String to be trimmed
  @return String with whitespace and characters in extraChars removed
  from the end.