Returns a map from a HTTP query string - Android java.net

Android examples for java.net:URL

Description

Returns a map from a HTTP query string

Demo Code

import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main{

    /**//from w  w  w . j a  v a 2s. c o  m
     * Returns a map from a HTTP query string
     *
     * @return Map of query parameters
     */
    public static Map<String, String> mapQueryString(String query) {
        String[] params = query.split("&");
        Map<String, String> map = new HashMap<String, String>();
        for (String param : params) {
            String[] split = param.split("=");
            map.put(split[0], split[1]);
        }
        return map;
    }

}

Related Tutorials