Here you can find the source of getQueryParameters(URL url)
Parameter | Description |
---|---|
url | a parameter |
Parameter | Description |
---|---|
UnsupportedEncodingException | an exception |
Map
with parameters names as map keys and parameters values as map values
public static Map<String, List<String>> getQueryParameters(URL url) throws UnsupportedEncodingException
//package com.java2s; import java.io.UnsupportedEncodingException; import java.net.URL; import java.net.URLDecoder; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; public class Main { /**//from w w w. j a v a 2s .com * Retrieve query parameters map from String representation of url * * @param url * @return - <code>Map</code> with parameters names as map keys and parameters values as map values * @throws UnsupportedEncodingException */ public static Map<String, List<String>> getQueryParameters(URL url) throws UnsupportedEncodingException { Map<String, List<String>> params = new HashMap<>(); String query = url.getQuery(); if (query != null) { for (String param : query.split("&")) { String pair[] = param.split("="); String key = URLDecoder.decode(pair[0], "UTF-8"); String value = null; if (pair.length > 1) { value = URLDecoder.decode(pair[1], "UTF-8"); } List<String> values = params.get(key); if (values == null) { values = new ArrayList<>(); params.put(key, values); } values.add(value); } } return params; } }