code: private static String trimTrailingWhitespace(String string) {
          int end = 0;
          char c;
  
          for (int i = string.length() - 1; i >= 0; i--) {
              c = string.charAt(i);
              if (!Character.isWhitespace(c)) {
                  end = i;
                  break;
              }
          }
  
          if (end == 0) {
              return string;
          }
  
          return string.substring(0, end + 1);
      }
docs: Returns a string that contains a copy of a specified string
  without trailing whitespaces.
  
  @param string the string to trim trailing whitespaces
  @return a string with trailing whitespaces trimmed