Here you can find the source of constructParameterString(TreeMap
private static String constructParameterString(TreeMap<String, String> pPostParms) throws UnsupportedEncodingException
//package com.java2s; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.util.TreeMap; public class Main { public static final String ENCODING = "UTF-8"; private static final String URL_EQUALS = "="; private static final String URL_AMPERSAND = "&"; private static String constructParameterString(TreeMap<String, String> pPostParms) throws UnsupportedEncodingException { StringBuilder sb = new StringBuilder(); if (pPostParms != null) { String cp = ENCODING; for (String thisKey : pPostParms.keySet()) { String thisVal = pPostParms.get(thisKey); if (!thisVal.isEmpty()) { if (!(sb.length() == 0)) { sb.append(URL_AMPERSAND); }//from ww w . j a v a 2 s. com sb.append(URLEncoder.encode(thisKey, cp)); sb.append(URL_EQUALS); sb.append(URLEncoder.encode(thisVal, cp)); } } } return sb.toString(); } }