Here you can find the source of queryStringFromMap(Map
public static String queryStringFromMap(Map<String, String> map) throws UnsupportedEncodingException
//package com.java2s; //License from project: Open Source License import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.util.Iterator; import java.util.Map; public class Main { public static String queryStringFromMap(Map<String, String> map) throws UnsupportedEncodingException { StringBuilder encodedData = new StringBuilder(); Iterator<Map.Entry<String, String>> mapIterator = map.entrySet().iterator(); while (mapIterator.hasNext()) { Map.Entry<String, String> entry = mapIterator.next(); if (mapIterator.hasNext()) { encodedData.append(String.format("%s&", urlEncodeEntry(entry))); } else { encodedData.append(urlEncodeEntry(entry)); }/*w w w. ja v a 2 s. c o m*/ } return encodedData.toString(); } public static String urlEncodeEntry(Map.Entry<String, String> entry) throws UnsupportedEncodingException { String encodedEntry = String.format("%s=%s", URLEncoder.encode(entry.getKey(), "utf-8"), URLEncoder.encode(entry.getValue(), "utf-8")); return encodedEntry; } }