簡體   English   中英

為什么Collections.enumeration帶有enumeration()方法

[英]Why Collections.enumeration comes with enumeration() method

在Collections Framework中,我們具有IteratorListIterator接口,這些接口用於迭代數據結構。 它們提供了完整的迭代功能。 但是我想知道為什么JDK在Collections類上有一個enumeration()方法。

誰能向我解釋這一點?

IteratorListIterator提供了用於遍歷集合的完整工具。 確實, Iterator文檔從本質上說是Iterator取代了Enumeration 每個集合都是一個Iterable ,因此可以使用Iterator 那么為什么會有方法Collections.enumeration對該Collections.enumeration產生Enumeration

原因是在原始Java 1.0版本中存在Enumeration ,並且直到在1.2中添加了collections框架后才引入Iterator 因此,有大量使用Enumeration的代碼和API。 添加了Collections.enumeration方法以(然后)使新的基於集合的代碼適應需要使用Enumeration舊代碼。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM