So what's an iterator ? So what is an Iterator ?
We could also do it using an iterator . Iterators are meant to solve that problem.The other way is to use an iterator . 在java中,iterator ()方法是工厂方法。 In Java, the iterator method on collections is a Factory Method. What happens here is, on line four, we have an iterator . We have seen that the for statement is such an iterator . An iterator is an object with a next method.Returns an Iterator over the elements of the source of this grouping. Forin结构能以几种方式与Iterator 互动。 The for in construct is able to interact with an Iterator in several ways. 迭代器都实现了一个叫做Iterator 的定义于标准库的trait。 Iterators all implement a trait named Iterator that is defined in the standard library. 注意:返回的Iterator 将处于未初始化状态,您必须先运行iterator . Note: The returned iterator will be in an uninitialized state, and you must run the iterator . 因为编译器仅仅能保证iterator 返回的是Object类型。 The compiler can onlyguarantee that an Object will be returned by the iterator . 要在Java中表示完全任意的惰性迭代器,您需要编写一个手动跟踪其状态的Iterator 。 To express a completely arbitrary lazy iterator in Java, you would need to write an Iterator that manually tracks its state. Iterable必须是一个序列,或iterator ,或其他支持迭代的对象。 Iterable should be in a series, an iterator , or various other object that backs iteration. 例如,Iterator 接口有一个“状态相关”的next方法,和相应的状态测试方法hasNext。 For example, the Iterator interface has the state-dependent method next and the corresponding state-testing method hasNext. 做到这一点最简单的方法是采用一个迭代器,它是一个对象,实现了Iterator 接口或ListIterator接口。 The better way is to employ an iterator, which is an object that implements either the Iterator or the ListIterator interface. 方法iterator ()中提供的迭代器并不保证以任意特定的顺序遍历优先级队列中的元素。 The Iterator provided in method iterator() is not guaranteed to traverse the elements of the priority queue in any particular order. 这是一个展示如何使用闭包来自定义行为同时又复用Iterator trait提供的迭代行为的绝佳例子。 This is a great example of how closures let you customize some behavior while reusing the iteration behavior that the Iterator trait provides. 对于上面的某些部分有一些比较有趣的分歧(特别是将Iterator 的使用替换为通过索引进行访问),具体讨论内容请查阅Reddit。 Some interesting disagreement about parts of the above(in particular replacing Iterator usage by access-by-index) has been discussed on Reddit here. 做到这一点最简单的方法是采用一个迭代器,它是一个对象,实现了Iterator 接口或ListIterator接口。 The easiest way to do this is to employ an iterator, which is an object that implements either the Iterator or the ListIterator interface. 我们说int*是InputIterator 的类属实参,因为int*能提供InputIterator 所要求的所有操作。 We say that int* is a model of Input Iterator because int* provides all of the operations that are specified by the Input Iterator requirements. String,Array,TypedArray,Map和Set都内置可迭代对象,因为它们的原型对象都有一个Symbol.iterator 方法。 String, Array, TypedArray, Map and Set are all built-in iterables, because their prototype objects all have a Symbol. iterator method. 我们这样来描述InputIterator 和BidirectionalIterator 的关系:BidirectionalIterator 是InputIterator 的refinement。 We describe the relationship between Input Iterator and Bidirectional Iterator by saying that Bidirectional Iterator is a refinement of Input Iterator . 实现此接口的内建类可以使用foreach进行遍历而无需实现IteratorAggregate或Iterator 接口。 Internal(built-in) classes that implement this interface can be used in a foreach construct and do not need to implement IteratorAggregate or Iterator .
Display more examples
Results: 29 ,
Time: 0.0181