Here you can find the source of buildQuery(final Map
public static String buildQuery(final Map<String, Object> query)
//package com.java2s; //License from project: Open Source License import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.util.Map; public class Main { public static String buildQuery(final Map<String, Object> query) { if ((query == null) || query.isEmpty()) {/*from w w w .jav a 2 s .com*/ return ""; } return query.entrySet().stream().map(entry -> createQueryElement(entry.getKey(), (entry.getValue() == null) ? null : entry.getValue().toString())).reduce((s1, s2) -> s1 + "&" + s2).orElse(""); } public static String createQueryElement(final String key, final String value) { String result = encodeUTF8(key); if (value != null) { result += "=" + encodeUTF8(value); } return result; } public static String encodeUTF8(final String str) { if (str == null) { return ""; } try { return URLEncoder.encode(str, "UTF-8"); } catch (final UnsupportedEncodingException e) { // should never be thrown throw new RuntimeException(e); } } }