Java URL Query Build getQueryParametersFromUrl(String url)

Here you can find the source of getQueryParametersFromUrl(String url)

Description

get Query Parameters From Url

License

Apache License

Declaration

public static Map<String, String> getQueryParametersFromUrl(String url)
            throws IllegalArgumentException 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.net.URI;
import java.util.Collections;
import java.util.HashMap;

import java.util.Map;

public class Main {
    public static Map<String, String> getQueryParametersFromUrl(String url)
            throws IllegalArgumentException {
        if (url == null)
            throw new IllegalArgumentException("url == null");
        URI uri = URI.create(url);
        String query = uri.getQuery();
        if (query == null)
            return Collections.emptyMap();
        String[] params = query.split("&");
        Map<String, String> paramMap = new HashMap<>();
        int mid;/*from   w  w w. ja v  a 2s .  co m*/
        for (String param : params) {
            mid = param.indexOf('=');
            if (mid != -1)
                paramMap.put(param.substring(0, mid),
                        param.substring(mid + 1));
        }
        return paramMap;
    }
}

Related

  1. getQueryParameter(String query, String key, String encoding)
  2. getQueryParameterMap(String queryString)
  3. getQueryParameters(URL url)
  4. getQueryParameters(URL url)
  5. getQueryParameters(URL url)
  6. getQueryParams(String httpUrl)
  7. getQueryParams(String query)
  8. getQueryParams(String s)
  9. getQueryParams(String url)