Java Map to String toString(Map m)

Here you can find the source of toString(Map m)

Description

to String

License

Apache License

Declaration

public static String toString(Map<String, String> m) 

Method Source Code

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

import java.util.Map;

public class Main {
    private static final String K_V_SEPARATOR = "=>";

    public static String toString(Map<String, String> m) {
        if (m.isEmpty()) {
            return "";
        }/*  w w w. j a v a  2 s  .  c om*/
        StringBuilder sb = new StringBuilder();
        int n = m.size();
        for (String key : m.keySet()) {
            sb.append("\"" + key + "\"" + K_V_SEPARATOR + "\"" + m.get(key)
                    + "\"");
            if (n > 1) {
                sb.append(", ");
                n--;
            }
        }
        return sb.toString();
    }
}

Related

  1. toString(Map m)
  2. toString(Map map)
  3. toString(Map map)
  4. toString(Map attrs)
  5. toString(Map attrs)
  6. toString(Map map)
  7. toString(Map params)
  8. toString(Map map)
  9. toString(Map map, StringBuilder sb)