Here you can find the source of toQueryString(Map, ?> map)
public static String toQueryString(Map<?, ?> map) throws UnsupportedEncodingException
//package com.java2s; //License from project: Open Source License import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.util.Map; public class Main { public static String toQueryString(Map<?, ?> map) throws UnsupportedEncodingException { StringBuilder sb = new StringBuilder(); for (Map.Entry<?, ?> entry : map.entrySet()) { if (sb.length() > 0) { sb.append("&"); }// w ww . ja v a 2 s .c o m sb.append(String.format("%s=%s", urlEncodeUTF8(entry.getKey().toString()), urlEncodeUTF8(entry.getValue().toString()))); } return sb.toString(); } static String urlEncodeUTF8(String s) throws UnsupportedEncodingException { return URLEncoder.encode(s, "UTF-8"); } }