Here you can find the source of mapToString(Map
Parameter | Description |
---|---|
map | A Map object containing <key, value> which need to be converted to query string |
public static String mapToString(Map<String, String> map)
//package com.java2s; //License from project: Open Source License import java.util.Map; public class Main { /**//from w w w. jav a 2 s . c o m * Converts a Map to Query String. This webService forms a query string from the map * * @param map A Map object containing <key, value> which need to be converted to query string * @return String Query string formed from the map */ public static String mapToString(Map<String, String> map) { StringBuilder stringBuilder = new StringBuilder(); for (String key : map.keySet()) { if (stringBuilder.length() > 0) { stringBuilder.append("&"); } String value = map.get(key); stringBuilder.append(((key != null) ? key : "")); if (value != null) { stringBuilder.append("="); stringBuilder.append((value != null) ? value : ""); } } return stringBuilder.toString(); } }