Here you can find the source of mapToQueryString(Map
public static String mapToQueryString(Map<String, Object> parameters, String charSet)
//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 mapToQueryString(Map<String, Object> parameters, String charSet) { String queryString = ""; if (parameters != null && !parameters.isEmpty()) { for (String key : parameters.keySet()) { try { Object value = parameters.get(key); if (value instanceof String) { queryString += key + "=" + URLEncoder.encode(value == null ? "" : value.toString(), charSet) + "&"; }//from www.j a v a 2 s . co m } catch (UnsupportedEncodingException e) { throw new IllegalArgumentException("invalid charset : " + charSet); } } if (queryString.length() > 0) { queryString = queryString.substring(0, queryString.length() - 1); } } return queryString; } }