split Url Query into Map<String,String> - Android Network

Android examples for Network:URL

Description

split Url Query into Map<String,String>

Demo Code


//package com.java2s;

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

public class Main {

    public static Map<String, String> splitUrlQuery(String query) {
        Map<String, String> result = new HashMap<String, String>();

        String[] pairs = query.split("&");
        if (pairs != null && pairs.length > 0) {
            for (String pair : pairs) {
                String[] param = pair.split("=", 2);
                if (param != null && param.length == 2) {
                    result.put(param[0], param[1]);
                }//from  ww w .  j a  va  2s .c  om
            }
        }

        return result;
    }
}

Related Tutorials