java.util.Iterator翻译

 
JavaTM 2 Platform
Std. Ed. v1.4.2

java.util
Interface Iterator

All Known Subinterfaces:
ListIterator
All Known Implementing Classes:
BeanContextSupport.BCSIterator

public interface Iterator

An iterator over a collection. Iterator takes the place of Enumeration in the Java collections framework. Iterators differ from enumerations in two ways: iterator重载了collection。在Java集合框架中Iterator用来替代Enumeration。Iterator和Enumeration 在以下两方面不同:

  • Iterators allow the caller to remove elements from the underlying collection during the iteration with well-defined semantics. Iterator允许调用者使用好的语义在迭代中从底层集合中删除元素。
  • Method names have been improved. 方法名称有改进。

This interface is a member of the Java Collections Framework. 该接口是Java集合框架成员。

Since:
1.2
See Also:
Collection , ListIterator , Enumeration

Method Summary
 booleanhasNext()
          Returns true if the iteration has more elements. 如果迭代中还有元素返回true。
 Objectnext()
          Returns the next element in the iteration. 返回迭代中的下一个元素。
 voidremove()
          Removes from the underlying collection the last element returned by the iterator (optional operation). 迭代器从底层集合中删除刚返回的元素(可选操作)。
 

Method Detail

hasNext

public boolean hasNext()
Returns true if the iteration has more elements. (In other words, returns true if next would return an element rather than throwing an exception.) 如果迭代中还有元素返回true。(换言之,如果next返回一个元素而不是抛出异常的话,返回true。)

Returns:
true if the iterator has more elements. 如果迭代中还有元素返回true。

next

public Object next()
Returns the next element in the iteration. 返回迭代中的下一个元素。

Returns:
the next element in the iteration. 迭代中下一个元素。
Throws:
NoSuchElementException - iteration has no more elements. 如果迭代中没有元素时抛出。

remove

public 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. 迭代器从底层集合中删除刚返回的元素(可选操作)。该方法只能在每次调用next后调用一次。 如果底层集合已被修改而迭代器正在进程中(除了调用本方法),则迭代器的行为不能确定。

Throws:
UnsupportedOperationException - if the remove operation is not supported by this Iterator. 如果Iterator不支持remove操作时抛出。
IllegalStateException - if the next method has not yet been called, or the remove method has already been called after the last call to the next method. next方法还未调用,或在上一次调用next后已调用过remove方法时抛出。

JavaTM 2 Platform
Std. Ed. v1.4.2

Submit a bug or feature
For further API reference and developer documentation, see Java 2 SDK SE Developer Documentation . That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.

Copyright 2003 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值