title: Is there any Java equivalent of PHP's http_build_query function?
body: <p>I have a Map with my data and want to build a query string with it, just like I would with http_build_query on PHP. I'm not sure if this code is the best implementation of it or if I'm forgetting something?</p>
  
  <pre><code>public String toQueryString(Map&lt;?, ?&gt; data) throws UnsupportedEncodingException {
      StringBuffer queryString = new StringBuffer();
  
      for (Entry&lt;?, ?&gt; pair : data.entrySet()) {
          queryString.append ( URLEncoder.encode ( (String) pair.getKey (), "UTF-8" ) + "=" );
          queryString.append ( URLEncoder.encode ( (String) pair.getValue (), "UTF-8" ) + "&amp;" );
      }
  
      if (queryString.length () &gt; 0) {
          queryString.deleteCharAt ( queryString.length () - 1 );
      }
  
      return queryString.toString ();
  }
  </code></pre>