Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
可以使用来自的迭代器来迭代 SortedMap myMap.entrySet().iterator()。但是这个迭代器是否保留了排序后的地图对象的顺序?
myMap.entrySet().iterator()
SortedMap 接口没有自己的方法来遍历条目。遍历条目的标准方法是什么?
对于键和条目,标准迭代器保证迭代顺序与键的自然顺序完全相同。这在文档中进行了说明,并且可以轻松测试。
另一方面,如果您有兴趣以与插入键相同的顺序保留键和条目的迭代顺序,那么您正在寻找LinkedHashMap。