code: public static URI setQueryParams(final URI initialUri, final Multimap<String, String> queryParams) {
          StringBuilder queryString = new StringBuilder();
          for (Map.Entry<String, String> entry: queryParams.entries()) {
              if (queryString.length() > 0) {
                  queryString.append("&");
              }
              queryString.append(entry.getKey()).append("=").append(entry.getValue());
          }
          try {
              if (initialUri.getHost() == null && initialUri.getAuthority() != null) {
                  return new URI(initialUri.getScheme(), initialUri.getAuthority(), initialUri.getPath(),
                                 queryString.toString(),
                                 initialUri.getFragment());
              } else {
                  return new URI(initialUri.getScheme(), initialUri.getUserInfo(), initialUri.getHost(),
                                 initialUri.getPort(),
                                 initialUri.getPath(),
                                 queryString.toString(), initialUri.getFragment());
              }
          } catch (URISyntaxException e) {
              throw ExceptionUtils.getRuntimeException(e);
          }
      }
docs: Construct a new uri by replacing query parameters in initialUri with the query parameters provided.
  
  @param initialUri the initial/template URI
  @param queryParams the new query parameters.