Parsing query strings in Java?

Java EE has ServletRequest.getParameterValues().

On non-EE platforms, URL.getQuery() simply returns a string.

What’s the normal way to properly parse the query string in a URL when not on Java EE?

public static Map> getUrlParameters(String url)

        throws UnsupportedEncodingException {

    Map> params = new HashMap>();

    String[] urlParts = url.split("\\?");

    if (urlParts.length > 1) {

        String query = urlParts[1];

        for (String param : query.split("&")) {

            String pair[] = param.split("=");

            String key = URLDecoder.decode(pair[0], "UTF-8");

            String value = "";

            if (pair.length > 1) {

                value = URLDecoder.decode(pair[1], "UTF-8");

            }

            List values = params.get(key);

            if (values == null) {

                values = new ArrayList();

                params.put(key, values);

            }

            values.add(value);

        }

    }

    return params;

}