Difference between Java Enumeration and Iterator

后端 未结 10 1780
庸人自扰
庸人自扰 2020-11-27 09:47

What is the exact difference between these two interfaces? Does Enumeration have benefits over using Iterator? If anyone could elaborate, a reference article would be appre

10条回答
  •  [愿得一人]
    2020-11-27 10:06

    The main different is Enumeration doesn't expose remove() method. Moreover, Iterator don't allow a simultaneously navigation and modification on an underlying object. They have a control to see if there are concurrent modifications or so, and hence takes more processing. So Enumeration's performance is virtually 50% faster than Iterator. If we need only navigation ignoring such a synchronization, just use Enumeration.

提交回复
热议问题