title: How can I append a query parameter to an existing URL?
body: <p>I'd like to append key-value pair as a query parameter to an existing URL. While I could do this by checking for the existence of whether the URL has a query part or a fragment part and doing the append by jumping though a bunch of if-clauses but I was wondering if there was clean way if doing this through the Apache Commons libraries or something equivalent.</p>
  
  <p><code>http://example.com</code> would be <code>http://example.com?name=John</code></p>
  
  <p><code>http://example.com#fragment</code> would be <code>http://example.com?name=John#fragment</code></p>
  
  <p><code>http://example.com?email=john.doe@email.com</code> would be <code>http://example.com?email=john.doe@email.com&amp;name=John</code></p>
  
  <p><code>http://example.com?email=john.doe@email.com#fragment</code> would be <code>http://example.com?email=john.doe@email.com&amp;name=John#fragment</code></p>
  
  <p>I've run this scenario many times before and I'd like to do this without breaking the URL in any way.</p>