Here you can find the source of mapToFormEncodedString(Map
private static String mapToFormEncodedString(Map<String, String> data)
//package com.java2s; //License from project: Open Source License import java.net.URLEncoder; import java.util.ArrayList; import java.util.List; import java.util.Map; public class Main { private static String mapToFormEncodedString(Map<String, String> data) { final List<String> acc = new ArrayList<String>(); for (Map.Entry<String, String> entry : data.entrySet()) { acc.add(encodeURIComponent(entry.getKey()) + "=" + encodeURIComponent(entry.getValue())); }//from w w w . j av a 2 s. c om return "?" + join(acc, "&"); } private static String encodeURIComponent(String component) { String result; try { result = URLEncoder.encode(component, "UTF-8").replaceAll("%28", "(").replaceAll("%29", ")") .replaceAll("\\+", "%20").replaceAll("%27", "'").replaceAll("%21", "!").replaceAll("%7E", "~"); } catch (java.io.UnsupportedEncodingException e) { result = component; } return result; } public static String join(List<String> list, String separator) { StringBuilder sb = new StringBuilder(); boolean first = true; for (final String str : list) { if (first) first = false; else sb.append(separator); sb.append(str); } return sb.toString(); } }