Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.io.UnsupportedEncodingException;

import java.net.URLEncoder;

import java.util.HashMap;
import java.util.Map;

public class Main {
    static String map2UrlQueryString(Map<String, Object> map) {
        StringBuilder sb = new StringBuilder();
        for (HashMap.Entry<String, Object> e : map.entrySet()) {
            try {
                sb.append(e.getKey());
                sb.append('=');
                sb.append(URLEncoder.encode(String.valueOf(e.getValue()), "UTF-8"));
            } catch (UnsupportedEncodingException e1) {
                e1.printStackTrace();
            }
            sb.append('&');
        }
        if (sb.length() == 0)
            return "";
        else
            return sb.substring(0, sb.length() - 1);
    }
}