Java URL Query Build mapToQueryString(Map queryString)

Here you can find the source of mapToQueryString(Map queryString)

Description

map To Query String

License

Apache License

Declaration

public static String mapToQueryString(Map<String, String> queryString) throws UnsupportedEncodingException 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.UnsupportedEncodingException;

import java.net.URLEncoder;

import java.util.Map;

public class Main {
    public static final String ENCODING_UTF_8 = "UTF-8";

    public static String mapToQueryString(Map<String, String> queryString) throws UnsupportedEncodingException {
        StringBuilder sb = new StringBuilder();
        for (Map.Entry<String, String> e : queryString.entrySet()) {
            if (sb.length() > 0) {
                sb.append('&');
            }//  ww  w  .ja  va 2s.  co m
            sb.append(URLEncoder.encode(e.getKey(), ENCODING_UTF_8)).append('=')
                    .append(URLEncoder.encode(e.getValue(), "UTF-8"));
        }
        return sb.toString();
    }
}

Related

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