Here you can find the source of mapToString(Map
private static String mapToString(Map<String, String> map)
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; import java.util.List; import java.util.Map; public class Main { private static String mapToString(Map<String, String> map) { StringBuilder stringBuilder = new StringBuilder(); if (null != map && !map.isEmpty()) { List<String> lst = new ArrayList<>(map.keySet()); for (String key : lst) { stringBuilder.append(key + "=" + map.get(key)); if (!key.equals(lst.get(lst.size() - 1))) { stringBuilder.append("&"); }//from ww w. j av a 2s. co m } } return stringBuilder.toString(); } }