/** * Returns a string representation of this {@code Hashtable} object in the form of a set of * entries, enclosed in braces and separated by the ASCII characters "<code> , </code>" * (comma and space). Each entry is rendered as the key, an equals sign {@code =}, and the * associated element, where the {@code toString} method is used to convert the key and element to * strings. * * @return a string representation of this hashtable */ public synchronized String toString() { int max = size() - 1; if (max == -1) return "{}"; StringBuilder sb = new StringBuilder(); Iterator<Map.Entry<K, V>> it = entrySet().iterator(); sb.append('{'); for (int i = 0; ; i++) { Map.Entry<K, V> e = it.next(); K key = e.getKey(); V value = e.getValue(); sb.append(key == this ? "(this Map)" : key.toString()); sb.append('='); sb.append(value == this ? "(this Map)" : value.toString()); if (i == max) return sb.append('}').toString(); sb.append(", "); } }
public String toString() { return key.toString() + "=" + value.toString(); }