首页 > 其他 > 详细

HashMap集合在遍历显示源码学习

时间:2018-10-24 00:53:46      阅读:151      评论:0      收藏:0      [点我收藏+]
重写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(‘ ‘);
        }
    }

HashMap集合在遍历显示源码学习

原文:http://blog.51cto.com/357712148/2308119

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!