Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

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

public class Main {
    private static Map<String, String> getQueryMapFromUrl(String url) {

        if (url.contains("?")) {
            url = url.split("\\?")[1];
        }

        return getQueryMap(url);
    }

    private static Map<String, String> getQueryMap(String query) {
        if (query == null) {
            return null;
        }
        String[] params = query.split("&");
        Map<String, String> map = new HashMap<String, String>();
        for (String param : params) {
            String[] keyname = param.split("=");

            if (keyname.length == 2) {
                String name = keyname[0];
                String value = keyname[1];
                map.put(name, value);
            } else if (keyname.length == 1) {
                String name = keyname[0];
                String value = "";
                map.put(name, value);
            }
        }
        return map;
    }
}