Parse Parameters from URL to map - Android java.net

Android examples for java.net:URL

Description

Parse Parameters from URL to map

Demo Code

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.util.Log;
import java.util.HashMap;

public class Main{

    public static HashMap<String, String> paserParams(String url) {
        String params = url.substring(url.indexOf("?") + 1);
        String[] arr = params.split("&");
        HashMap<String, String> maps = new HashMap<String, String>();
        for (String s : arr) {
            maps.put(s.substring(0, s.indexOf("=")),
                    s.substring(s.indexOf("=") + 1));
        }/*  w  ww. ja va2  s  .  com*/
        return maps;
    }

}

Related Tutorials