Here you can find the source of serializeParameters(final Map
public static String serializeParameters(final Map<String, String> parameters)
//package com.java2s; // Licensed under the MIT license. See sibling License.txt file import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.util.Iterator; import java.util.Map; public class Main { public static final String UTF_8 = "UTF-8"; public static String serializeParameters(final Map<String, String> parameters) { try {//from w w w . j av a 2s .c o m final StringBuilder sb = new StringBuilder(); final Iterator<Map.Entry<String, String>> iterator = parameters.entrySet().iterator(); if (iterator.hasNext()) { Map.Entry<String, String> entry; String key; String encodedKey; String value; String encodedValue; entry = iterator.next(); key = entry.getKey(); encodedKey = URLEncoder.encode(key, UTF_8); sb.append(encodedKey); value = entry.getValue(); if (value != null) { encodedValue = URLEncoder.encode(value, UTF_8); sb.append('=').append(encodedValue); } while (iterator.hasNext()) { sb.append('&'); entry = iterator.next(); key = entry.getKey(); encodedKey = URLEncoder.encode(key, UTF_8); sb.append(encodedKey); value = entry.getValue(); if (value != null) { encodedValue = URLEncoder.encode(value, UTF_8); sb.append('=').append(encodedValue); } } } return sb.toString(); } catch (final UnsupportedEncodingException e) { throw new Error(e); } } }