关于Enumeration和Iterator的区别.

有如下代码:java.util.Enumerationparams=this.getServletConfig().getInitParameterNames();如果这... 有如下代码:
java.util.Enumeration params = this.getServletConfig().getInitParameterNames();
如果这样写就是正确的.但是如果我换成.
java.util.Iterator params = this.getServletConfig().getInitParameterNames();
eclipse就会报错,说是enumeration不能转换成iterator类型.
请问是为什么?明明enumeration比iterator还要老嘛.为什么他确能用而iterator不能用.
展开
 我来答
love__shuai
2008-09-10 · TA获得超过563个赞
知道小有建树答主
回答量:875
采纳率:0%
帮助的人:0
展开全部
this.getServletConfig().getInitParameterNames();
这个方法的返回值必须是枚举类型的,具体这两个的差别好像是访问集合类的时候,Iterator能用remove()的方法进行删除,而Enumeration则不能进行删除~
你想如果用Iterator你把初始化参数删除了,那也不符合常理吧~
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
舒仕福
2023-07-11 广告
eor有以下两种含义:1. eor是计算机术语,表示二进制异或运算。在计算机逻辑运算中,算术逻辑执行二进制按位异或运算,两数执行异或后相同位结果为0,不同位结果为1。2. eor也表示在任何时期,向地层中注入流体、能量,以提高产量或采收率的... 点击进入详情页
本回答由舒仕福提供
编程大米饭
2008-09-10
知道答主
回答量:15
采纳率:0%
帮助的人:12.9万
展开全部
An iterator over a collection. Iterator takes the place of Enumeration in the Java collections framework. Iterators differ from enumerations in two ways:
1.Iterators allow the caller to remove elements from the underlying collection during the iteration with well-defined semantics.
void remove() :Removes from the underlying collection the last element returned by the iterator (optional operation).This method can be called only once per call to next. The behavior of an iterator is unspecified if the underlying collection is modified while the iteration is in progress in any way other than by calling this method。
2.Method names have been improved

/×××××××××××××××××××××××××××××/
java.util
Interface Iterator<E>

All Known Subinterfaces:
ListIterator<E>, XMLEventReader
-------------------------------------------------
java.util
Interface Enumeration<E>

All Known Subinterfaces:
NamingEnumeration<T>
/×××××××××××××××××××××××××××××/
An object that implements the Enumeration interface generates a series of elements, one at a time. Successive calls to the nextElement method return successive elements of the series.

参考资料: JDK6.0

已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式