Here you can find the source of queryStringToMap(String query, Boolean decode)
public static Map<String, String> queryStringToMap(String query, Boolean decode) throws UnsupportedEncodingException
//package com.java2s; //License from project: Open Source License import java.io.UnsupportedEncodingException; import java.net.URLDecoder; import java.util.HashMap; import java.util.Map; public class Main { public static Map<String, String> queryStringToMap(String query) throws UnsupportedEncodingException { HashMap<String, String> hashMap = new HashMap<String, String>(); String[] encodedPairs = query.split("&"); for (String pair : encodedPairs) { String[] splitPair = pair.split("=", -1); if (splitPair.length != 2) { throw new RuntimeException("query string not properly formatted"); }/*from w w w. j a v a 2s .c o m*/ String encodedKey = splitPair[0]; String encodedValue = splitPair[1]; hashMap.put(URLDecoder.decode(encodedKey, "utf-8"), URLDecoder.decode(encodedValue, "utf-8")); } return hashMap; } public static Map<String, String> queryStringToMap(String query, Boolean decode) throws UnsupportedEncodingException { HashMap<String, String> hashMap = new HashMap<String, String>(); String[] encodedPairs = query.split("&"); for (String pair : encodedPairs) { String[] splitPair = pair.split("=", -1); if (splitPair.length != 2) { throw new RuntimeException("query string not properly formatted"); } String encodedKey = splitPair[0]; String encodedValue = splitPair[1]; if (decode) { hashMap.put(URLDecoder.decode(encodedKey, "utf-8"), URLDecoder.decode(encodedValue, "utf-8")); } else { hashMap.put(encodedKey, encodedValue); } } return hashMap; } }