Java URL Query Build mapToQueryString(Map parameters, String charSet)

Here you can find the source of mapToQueryString(Map parameters, String charSet)

Description

map To Query String

License

Open Source License

Declaration

public static String mapToQueryString(Map<String, Object> parameters, String charSet) 

Method Source Code

//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 mapToQueryString(Map<String, Object> parameters, String charSet) {
        String queryString = "";
        if (parameters != null && !parameters.isEmpty()) {
            for (String key : parameters.keySet()) {
                try {
                    Object value = parameters.get(key);
                    if (value instanceof String) {
                        queryString += key + "=" + URLEncoder.encode(value == null ? "" : value.toString(), charSet)
                                + "&";
                    }//from www.j a v  a  2  s  .  co  m
                } catch (UnsupportedEncodingException e) {
                    throw new IllegalArgumentException("invalid charset : " + charSet);
                }
            }
            if (queryString.length() > 0) {
                queryString = queryString.substring(0, queryString.length() - 1);
            }
        }
        return queryString;
    }
}

Related

  1. getQueryUrl(String word)
  2. getQueryUrl(String word, Integer page)
  3. getQueryURL(URL baseUrl, String[] parameters)
  4. getQueryValues(String input)
  5. mapToQueryString(Map parameters, String charSet)
  6. mapToQueryString(Map queryString)
  7. toQueryString(Map map)
  8. toQueryString(Map requestMap)