Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

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

import java.util.Map;
import java.util.Set;

public class Main {
    static public String assemblyUrlByCommon(String url, Map<String, String> params) {
        if (params == null && params.size() == 0) {
            return url;
        } else {
            StringBuilder sb = new StringBuilder(url);
            sb.append("?");

            Set<String> keys = params.keySet();
            int i = 0;
            for (String key : keys) {
                String value = params.get(key);
                sb.append(key).append("=").append(value);
                if (i != keys.size() - 1) {
                    sb.append("&");
                }
                i++;
            }
            return sb.toString();
        }
    }
}