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 android.text.TextUtils;

public class Main {

    public static String addParamToUrl(String url, String key, Object value) {
        if (TextUtils.isEmpty(url)) {
            return null;
        }
        String tmpKey = key + "=";
        if (url.indexOf(tmpKey) != -1) {
            String[] tmp = url.split(tmpKey);
            if (tmp.length > 1) {
                if (tmp[1].indexOf("&") != -1) {
                    String subStr = tmp[1].substring(tmp[1].indexOf("&"), tmp[1].length());
                    url = tmp[0] + tmpKey + value + subStr;
                } else {
                    url = tmp[0] + tmpKey + value;
                }
            }
        } else {
            if (url.indexOf("?") == -1) {
                url += "?" + key + "=" + value;
            } else {
                url += "&" + key + "=" + value;
            }
        }
        return url;
    }

    public static boolean isEmpty(String str) {
        return str == null || str.length() == 0;
    }
}