how to remove a query parameter from a query string
<p>I am using <a href="https://docs.oracle.com/javaee/7/api/javax/ws/rs/core/UriBuilder.html" rel="noreferrer">UriBuilder</a> to remove a parameter from a URI:</p>

<pre><code>public static URI removeParameterFromURI(URI uri, String param) {
    UriBuilder uriBuilder = UriBuilder.fromUri(uri);
    return uriBuilder.replaceQueryParam(param, "").build();
}

public static String removeParameterFromURIString(String uriString, String param) {
    try {
        URI uri = removeParameterFromURI(new URI(uriString), param);
        return uri.toString();
    } catch (URISyntaxException e) {
        throw new RuntimeException(e);
    }
}
</code></pre>

<p>The above sort of works and modifies:</p>

<p><a href="http://a.b.c/d/e/f?foo=1&amp;bar=2&amp;zar=3" rel="noreferrer">http://a.b.c/d/e/f?foo=1&amp;bar=2&amp;zar=3</a></p>

<p>&hellip; into:</p>

<p><a href="http://a.b.c/d/e/f?bar=&amp;foo=1&amp;zar=3" rel="noreferrer">http://a.b.c/d/e/f?bar=&amp;foo=1&amp;zar=3</a></p>

<p>But it has the following issues:</p>

<ol>
<li>It messes up the order of the parameters. I know that the order is not relevant but it still bothers me.</li>
<li>it doesn't fully remove the parameter, it just sets its value to the empty string. I would prefer is the parameter is completely removed from the query string.</li>
</ol>

<p>Is there some standard or commonly used library that can achieve the above neatly without having to parse and hack the query string myself?</p>