Here you can find the source of toString(Map
public static String toString(Map<Object, String> m)
//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<Object, String> m) { if (m == null || m.isEmpty()) { return ""; }/* w w w . ja v a 2 s.com*/ StringBuilder sb = new StringBuilder(); int n = m.size(); for (Object key : m.keySet()) { String stringKey = String.valueOf(key); sb.append('"').append(escapeQuotes(stringKey)).append('"'); sb.append(K_V_SEPARATOR); sb.append('"').append(escapeQuotes(String.valueOf(m.get(key)))) .append('"'); if (n > 1) { sb.append(", "); n--; } } return sb.toString(); } private static String escapeQuotes(String text) { return text.replaceAll("\"", "'"); } }