
关于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不能用. 展开
java.util.Enumeration params = this.getServletConfig().getInitParameterNames();
如果这样写就是正确的.但是如果我换成.
java.util.Iterator params = this.getServletConfig().getInitParameterNames();
eclipse就会报错,说是enumeration不能转换成iterator类型.
请问是为什么?明明enumeration比iterator还要老嘛.为什么他确能用而iterator不能用. 展开
2个回答
展开全部
this.getServletConfig().getInitParameterNames();
这个方法的返回值必须是枚举类型的,具体这两个的差别好像是访问集合类的时候,Iterator能用remove()的方法进行删除,而Enumeration则不能进行删除~
你想如果用Iterator你把初始化参数删除了,那也不符合常理吧~
这个方法的返回值必须是枚举类型的,具体这两个的差别好像是访问集合类的时候,Iterator能用remove()的方法进行删除,而Enumeration则不能进行删除~
你想如果用Iterator你把初始化参数删除了,那也不符合常理吧~
已赞过
已踩过<
评论
收起
你对这个回答的评价是?

2023-07-11 广告
eor有以下两种含义:1. eor是计算机术语,表示二进制异或运算。在计算机逻辑运算中,算术逻辑执行二进制按位异或运算,两数执行异或后相同位结果为0,不同位结果为1。2. eor也表示在任何时期,向地层中注入流体、能量,以提高产量或采收率的...
点击进入详情页
本回答由舒仕福提供
展开全部
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.
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
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询