Here you can find the source of encode(HashMap
public static String encode(HashMap<String, Object> map)
//package com.java2s; /* /*from w ww .j av a 2 s .co m*/ * Copyright (C) 2014 Peter Cai * * This file is part of BlackLight * * BlackLight is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * BlackLight is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with BlackLight. If not, see <http://www.gnu.org/licenses/>. */ import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.util.HashMap; import java.util.Set; public class Main { public static String encode(HashMap<String, Object> map) { if (map == null) { return null; } StringBuilder str = new StringBuilder(); Set<String> keys = map.keySet(); boolean first = true; for (String key : keys) { Object value = map.get(key); if (first) { first = false; } else { str.append("&"); } try { str.append(URLEncoder.encode(key, "UTF-8")).append("=") .append(URLEncoder.encode(value.toString(), "UTF-8")); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } return str.toString(); } }