Java Utililty Methods Map to String

List of utility methods to do Map to String

Description

The list of methods to do Map to String are organized into topic(s).

Method

StringmapToString(Map map)
map To String
LinkedList<String> pairs = new LinkedList<String>();
ArrayList<String> keyList = new ArrayList<String>(map.keySet());
Collections.sort(keyList);
for (String s : keyList) {
    Object value = map.get(s);
    String valueStr = toString(value);
    pairs.add(s + ": " + valueStr);
return "{" + join(", ", pairs.toArray()) + "}";
StringmapToString(Map criteria)
Create a string representation of Map.
StringBuilder criteriaMapStr = new StringBuilder();
if ((null == criteria) || (criteria.isEmpty())) {
    criteriaMapStr.append("[]");
} else {
    Iterator<Entry<String, String>> iterator = criteria.entrySet().iterator();
    Entry<String, String> entry;
    criteriaMapStr.append("[");
    while (iterator.hasNext()) {
...
StringMapToString(Map map)
Map To String
String result = "";
Iterator<String> keySetIterator = map.keySet().iterator();
while (keySetIterator.hasNext()) {
    String key = keySetIterator.next();
    result += "|" + key + ":" + map.get(key);
return result;
StringmapToString(Map map)
map To String
StringBuilder stringBuilder = new StringBuilder();
if (null != map && !map.isEmpty()) {
    List<String> lst = new ArrayList<>(map.keySet());
    for (String key : lst) {
        stringBuilder.append(key + "=" + map.get(key));
        if (!key.equals(lst.get(lst.size() - 1))) {
            stringBuilder.append("&");
return stringBuilder.toString();
StringmapToString(Map map)
Convert a map to a string of key/val pairs of the form key1=val1, separated by semicolons.
String ret = "";
for (String key : map.keySet()) {
    ret += key + "=" + map.get(key) + "; ";
return ret;
StringmapToString(Map map)
map To String
StringBuilder sb = new StringBuilder();
sb.append("[");
if (map != null && map.size() > 0) {
    int i = 0;
    for (Map.Entry<String, String> entry : map.entrySet()) {
        if (i + 1 == map.size()) {
            sb.append(entry.getKey()).append("=").append(entry.getValue());
        } else {
...
StringmapToString(Map map)
map To String
StringBuffer buf = new StringBuffer();
for (String key : map.keySet()) {
    buf.append(key).append('=');
    if (map.containsKey(key)) {
        buf.append(map.get(key));
    buf.append("\n");
return buf.toString();
StringmapToString(Map map)
Converts a Map to Query String.
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) {
...
StringmapToString(Map parameterMap)
map To String
StringBuilder sb = new StringBuilder().append('[');
for (Map.Entry<String, String[]> entry : parameterMap.entrySet()) {
    sb.append(entry.getKey()).append(" -> ");
    String[] value = entry.getValue();
    if (value != null) {
        sb.append("(");
        appendTo(sb, Arrays.asList(value), ",");
        sb.append(")");
...
StringmapToString(Map map, String splitter)
map To String
if (map.size() == 0)
    return "";
Iterator iterator = map.keySet().iterator();
String key = (String) iterator.next();
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(key);
stringBuilder.append(":");
stringBuilder.append(map.get(key));
...