Java URL Parameter Builder mapToString(Map map)

Here you can find the source of mapToString(Map map)

Description

map To String

License

Apache License

Declaration

public static String mapToString(Map<String, String> map) 

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 String mapToString(Map<String, String> map) {
        StringBuilder stringBuilder = new StringBuilder();

        for (String key : map.keySet()) {
            if (stringBuilder.length() > 0) {
                stringBuilder.append("&");
            }//from   www .j  a  va 2  s . co  m
            String value = map.get(key);
            try {
                stringBuilder.append((key != null ? URLEncoder.encode(key, "UTF-8") : ""));
                stringBuilder.append("=");
                stringBuilder.append(value != null ? URLEncoder.encode(value, "UTF-8") : "");
            } catch (UnsupportedEncodingException e) {
                throw new RuntimeException("This method requires UTF-8 encoding support", e);
            }
        }

        return stringBuilder.toString();
    }
}

Related

  1. map2String(Map params)
  2. mapToFormEncodedString(Map data)
  3. mapToFormString(Map map)
  4. mapToStr( Map map)
  5. mapToStr(Map map)
  6. parse(final Map> parameters, final Scanner scanner, final String encoding)
  7. parse_parameters(String input)
  8. parseGetParameters(HttpExchange exchange)
  9. parseParameters(final String value)