LinkedHashMap和LinkedHashSet中没有ListIterator [英] No ListIterator in LinkedHashMap and LinkedHashSet

查看:107
本文介绍了LinkedHashMap和LinkedHashSet中没有ListIterator的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尽管文档特别声明了LinkedHashMap和LinkedHashSet

Although the documentation specifically states that both LinkedHashMap and LinkedHashSet

维护一个双向链接列表,贯穿其所有条目

maintains a doubly-linked list running through all of its entries

我不明白为什么这些实现不返回ListIterator来导航下一个和上一个. 有人知道引擎盖下的局限性吗?

I don't understand why these implementations do not return a ListIterator to navigate with next and previous. Is anyone aware of the limitations under the hood?

推荐答案

ListIterator提供了在迭代器的当前位置"插入它们的可能性.但这破坏了LinkedHashMap/Set本身施加的顺序,因为他们的合同说列表顺序将严格等于插入顺序.

A ListIterator opens the possibility of inserting through them "at the current position of the iterator". But that breaks the ordering imposed by the LinkedHashMap/Set itself because their contract says that the list order will be strictly equal to the insertion order.

这篇关于LinkedHashMap和LinkedHashSet中没有ListIterator的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆