Java tutorial
//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; import java.util.Map.Entry; public class Main { public static String buildEncodedQueryString(HashMap<String, String> requestParams) { String queryString = "?"; if (requestParams == null) { return null; } Iterator<Entry<String, String>> it = requestParams.entrySet().iterator(); while (it.hasNext()) { Map.Entry<String, String> pairs = (Map.Entry<String, String>) it.next(); try { queryString += URLEncoder.encode(pairs.getKey().toString(), "UTF-8") + "=" + URLEncoder.encode(pairs.getValue().toString(), "UTF-8") + "&"; } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } } if (queryString.length() > 0) queryString = queryString.substring(0, queryString.length() - 1); return queryString; } }