android maniac android maniac - 1 year ago 93
Java Question

Getting URL parameter in java and extract a specific text from that URL

I have a URL and I need to get the value of v from this URL.
Here is my URL:

Any useful and fruitful help is highly appreciated..

Answer Source

I think the one of the easiest ways out would be to parse the string returned by URL.getQuery() as

public static Map<String, String> getQueryMap(String query)  
    String[] params = query.split("&");  
    Map<String, String> map = new HashMap<String, String>();  
    for (String param : params)  
        String name = param.split("=")[0];  
        String value = param.split("=")[1];  
        map.put(name, value);  
    return map;  

You can use the map returned by this function to retrieve the value keying in the parameter name.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download