Here you can find the source of buildUrl(String url, HashMap
private static String buildUrl(String url, HashMap<String, String> params) throws UnsupportedEncodingException
//package com.java2s; //License from project: Apache License import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.util.HashMap; import java.util.Iterator; import java.util.Map.Entry; public class Main { private static String buildUrl(String url, HashMap<String, String> params) throws UnsupportedEncodingException { StringBuilder urlString = new StringBuilder(url); if (params.isEmpty()) { return urlString.toString(); }//w ww . ja va 2s.com urlString.append("?"); Iterator<Entry<String, String>> it = params.entrySet().iterator(); while (it.hasNext()) { Entry<String, String> entry = it.next(); urlString.append(URLEncoder.encode(entry.getKey(), "UTF-8")); urlString.append("=").append(URLEncoder.encode(entry.getValue(), "UTF-8")); urlString.append(it.hasNext() ? '&' : ""); } return urlString.toString(); } }