code: public static String addParam(String url, String name, String value,
                                    String charset) throws UnsupportedEncodingException {
          StringBuilder newUrl = new StringBuilder(url);
  
          if (!url.endsWith("?") && !url.endsWith("&")) {
              if (url.contains("?")) {
                  newUrl.append('&');
              } else {
                  newUrl.append('?');
              }
          }
  
          newUrl.append(URLEncoder.encode(name, charset));
          newUrl.append('=');
          newUrl.append(URLEncoder.encode(value, charset));
  
          return newUrl.toString();
      }
docs: Adds a query string param to the URL, adding a '?' if there's no query string yet.
  
  @param url       the URL
  @param name      the name of the param
  @param value     the value of the param
  @param charset   the charset to encode the param key/value with
  
  @return the URL with the query string param appended