public static String removeQueryParameter(String url, String key) {
    String[] urlParts = url.split("\\?");

    if (urlParts.length == 2) {
      Map<String, List<String>> paramMap = extractParametersFromQueryString(urlParts[1]);
      if (paramMap.containsKey(key)) {
        String queryValue = paramMap.get(key).get(0);
        String result = url.replace(key + "=" + queryValue, "");
        // improper separators have to be fixed
        // @TODO find a better way to solve this
        result = result.replace("?&", "?").replace("&&", "&");
        if (result.endsWith("&")) {
          return result.substring(0, result.length() - 1);
        } else {
          return result;
        }
      }
    }
    return url;
  }
public static String removeQueryParameter ( String url , String key ) { String [ ] urlParts = url . split ( "\\?" ) ; if ( urlParts . length == 2 ) { Map < String , List < String > > paramMap = extractParametersFromQueryString ( urlParts [ 1 ] ) ; if ( paramMap . containsKey ( key ) ) { String queryValue = paramMap . get ( key ) . get ( 0 ) ; String result = url . replace ( key + "=" + queryValue , "" ) ; result = result . replace ( "?&" , "?" ) . replace ( "&&" , "&" ) ; if ( result . endsWith ( "&" ) ) { return result . substring ( 0 , result . length ( ) - 1 ) ; } else { return result ; } } } return url ; }
Remove the given key from the url query string and return the new URL as String.

@param url
The URL from which parameters are extracted.
@param key
the key, that should be removed
@return the modified URL as String