重写tostring,,方法
源码分析
public String toString() {
Iterator<Entry<K,V>> i = entrySet().iterator();
if (! i.hasNext())
return "{}";
StringBuilder sb = new StringBuilder();
sb.append(‘{‘);
for (;;) {
Entry<K,V> e = i.next();
K key = e.getKey();
V value = e.getValue();
sb.append(key == this ? "(this Map)" : key);
sb.append(‘=‘);
sb.append(value == this ? "(this Map)" : value);
if (! i.hasNext())
return sb.append(‘}‘).toString();
sb.append(‘,‘).append(‘ ‘);
}
}
原文地址:http://blog.51cto.com/357712148/2308119
时间: 2024-10-11 04:08:51