Java URL Query Split splitQuery(String query)

Here you can find the source of splitQuery(String query)

Description

split Query

License

Open Source License

Declaration

private static Map<String, String> splitQuery(String query) throws UnsupportedEncodingException 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;

import java.util.HashMap;
import java.util.Map;

public class Main {
    private static Map<String, String> splitQuery(String query) throws UnsupportedEncodingException {
        if (query == null || query.isEmpty()) {
            return new HashMap<>();
        } else {//from  w  w  w.  j  av  a 2  s.c  o m
            String[] params = query.split("&");
            Map<String, String> map = new HashMap<>();
            for (String param : params) {
                String[] split = param.split("=");
                map.put(URLDecoder.decode(split[0], "UTF-8"),
                        URLDecoder.decode(split.length > 1 ? split[1] : "", "UTF-8"));
            }
            return map;
        }
    }
}

Related

  1. splitQuery(String query)
  2. splitQuery(String queryString)
  3. splitQuery(String url)
  4. splitQuery(URL url)
  5. splitQuery(URL url)