Java Utililty Methods URL Query Build

List of utility methods to do URL Query Build

Description

The list of methods to do URL Query Build are organized into topic(s).

Method

StringcreateQueryString(Map options)
Given a key / value mapping, create and return a URI formatted query string that is valid and can be appended to a URI.
try {
    if (options.size() > 0) {
        StringBuffer rc = new StringBuffer();
        boolean first = true;
        for (String key : options.keySet()) {
            if (first) {
                first = false;
            } else {
...
StringcreateQueryString(Map params)
Given a java.util.Map of params, construct a query string
StringBuilder queryString = new StringBuilder();
boolean first = true;
for (Map.Entry<String, String> entry : params.entrySet()) {
    String paramName = entry.getKey();
    String paramValue = entry.getValue();
    if (first) {
        first = false;
    } else {
...
StringcreateQueryString(Map params)
Create a query String using the given parameters.
if (null == params || params.isEmpty()) {
    return "";
StringBuilder sb = new StringBuilder();
if (!params.isEmpty()) {
    sb.append("?");
    try {
        for (Iterator<Entry<String, String>> iterator = params.entrySet().iterator(); iterator.hasNext();) {
...
StringcreateQueryStringForParameters(Map parameters)
create Query String For Parameters
StringBuilder parametersAsQueryString = new StringBuilder();
if (parameters != null) {
    boolean firstParameter = true;
    for (String parameterName : parameters.keySet()) {
        if (!firstParameter) {
            parametersAsQueryString.append(PARAMETER_DELIMITER);
        parametersAsQueryString.append(parameterName).append(PARAMETER_EQUALS_CHAR)
...
StringBuffercreateQueryStringFromMap(Map m, String ampersand, boolean encode)
Builds a query string from a given map of parameters.
final StringBuffer result = new StringBuffer("");
final Set<?> entrySet = m.entrySet();
final Iterator<?> entrySetIterator = entrySet.iterator();
while (entrySetIterator.hasNext()) {
    final Map.Entry<?, ?> entry = (Map.Entry<?, ?>) entrySetIterator.next();
    final Object o = entry.getValue();
    if (o == null) {
        append(entry.getKey(), "", result, ampersand, encode);
...
StringgetQuery(Map params, String encode)
get Query
StringBuffer query = new StringBuffer();
for (Iterator iter = params.keySet().iterator(); iter.hasNext();) {
    String name = (String) iter.next();
    String value = (String) params.get(name);
    try {
        value = URLEncoder.encode(value, encode);
    } catch (UnsupportedEncodingException e) {
    query.append(name);
    query.append("=");
    query.append(value);
    query.append("&");
return query.toString();
StringgetQuery(URL theURL)
Returns the query string of the URL.
String file = theURL.getFile();
String query = null;
if (file != null) {
    int q = file.lastIndexOf('?');
    if (q != -1) {
        query = file.substring(q + 1);
    } else {
        query = "";
...
HashtablegetQueryFromURL(URL url)
get Query From URL
if (url == null || url.getQuery() == null)
    return new Hashtable<String, String>();
Hashtable<String, String> returned = new Hashtable<String, String>();
StringTokenizer st = new StringTokenizer(url.getQuery(), "&");
while (st.hasMoreTokens()) {
    StringTokenizer subSt = new StringTokenizer(st.nextToken(), "=");
    String key = null, value = null;
    if (subSt.hasMoreTokens())
...
MapgetQueryMap(String query)
get Query Map
String[] params = query.split("&");
Map<String, String> map = new HashMap<>();
for (String param : params) {
    String name = null;
    final String[] paramParts = param.split("=");
    try {
        name = URLDecoder.decode(paramParts[0], "utf-8");
    } catch (UnsupportedEncodingException e) {
...
MapgetQueryMap(String urlString)
Parses a URLs query parameters into a Map for easier parsing of options.
return getQueryMap(getUrlObject(urlString));