Java Map to String mapToString(Map map)

Here you can find the source of mapToString(Map map)

Description

Converts a Map to Query String.

License

Open Source License

Parameter

Parameter Description
map A Map object containing <key, value> which need to be converted to query string

Return

String Query string formed from the map

Declaration

public static String mapToString(Map<String, String> map) 

Method Source Code

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

import java.util.Map;

public class Main {
    /**//from   w  w  w. jav a 2  s . c  o m
     * Converts a Map to Query String. This webService forms a query string from the map
     * 
     * @param map A Map object containing <key, value> which need to be converted to query string
     * @return String Query string formed from the map
     */
    public static String mapToString(Map<String, String> map) {
        StringBuilder stringBuilder = new StringBuilder();

        for (String key : map.keySet()) {
            if (stringBuilder.length() > 0) {
                stringBuilder.append("&");
            }

            String value = map.get(key);
            stringBuilder.append(((key != null) ? key : ""));

            if (value != null) {
                stringBuilder.append("=");
                stringBuilder.append((value != null) ? value : "");
            }
        }
        return stringBuilder.toString();
    }
}

Related

  1. mapToString(Map acs)
  2. mapToString(Map m)
  3. mapToString(Map map)
  4. mapToString(Map criteria)
  5. mapToString(Map map)
  6. mapToString(Map map)
  7. mapToString(Map map)
  8. MapToString(Map map)
  9. mapToString(Map map)