Java URL Parameter Builder map2String(Map params)

Here you can find the source of map2String(Map params)

Description

map String

License

Open Source License

Declaration

private static String map2String(Map<String, String> params) 

Method Source Code


//package com.java2s;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

import java.util.Map;
import java.util.Map.Entry;

public class Main {
    private static String map2String(Map<String, String> params) {
        int count = 0;
        StringBuilder builder = new StringBuilder();
        for (Entry<String, String> entry : params.entrySet()) {
            if (count > 0) {
                builder.append("&");
            }//from  www . j a  v a2 s  .  c o m
            builder.append(entry.getKey());
            builder.append("=");
            try {
                if (null == entry.getValue()) {
                    builder.append(entry.getValue());
                } else {
                    builder.append(URLEncoder.encode(entry.getValue(), "utf-8"));
                }
            } catch (UnsupportedEncodingException e) {
                builder.append(entry.getValue());
            }
            count++;
        }
        return builder.toString();
    }
}

Related

  1. getUrlParameters(String url)
  2. getUrlParameters(String url)
  3. getUrlParameters(String url)
  4. getUrlParameters(String url)
  5. getURLParameters(URI uri)
  6. mapToFormEncodedString(Map data)
  7. mapToFormString(Map map)
  8. mapToStr( Map map)
  9. mapToStr(Map map)