Here you can find the source of toString(Map
public static <K, V> String toString(Map<K, V> map)
//package com.java2s; //License from project: Apache License import java.util.Map; public class Main { public static <K, V> String toString(Map<K, V> map) { if (map == null) return ""; if (map.isEmpty()) return "{}"; StringBuilder result = new StringBuilder(); for (Map.Entry<K, V> entry : map.entrySet()) { result.append(String.format(", %s -> %s ", entry.getKey().toString(), entry.getValue().toString())); }// w ww . j a v a 2 s . c o m return "{" + result.substring(1) + "}"; } }