但是,Iterator 比Enumeration更安全,因为其他线程在一个迭代器进行遍历时不能修改集合对象。 The Iterator is much safer than Enumeration as it always blocks other threads to alter the collection object.LinkedList<E>可以使用iterator 实现固定时间插入或删除,但只能顺序访问元素。 LinkedList<E> allows for constant-time insertions or removals using iterators , but only sequential access of elements. 使用LinkedList其中一个好处可以重用已有iterator 插入和删除元素。 The main benefits of using a LinkedList arise when you re-use existing iterators to insert and remove elements. 第二种方法是使用entrySet(),通过for循环或者结合Iterator .hasNext()方法使用while循环遍历它们。 Second method involves using entrySet() and iterating over them either by using for each loop or while with Iterator . hasNext() method. 真正关心如何遍历的是iteratorobject,它的两个方法构成了iterator protocol。 Iterator objects are required to support two main methods that form the iterator protocol.
Iterator trait中定义了另一类方法,被称为迭代器适配器(iterator adaptors),他们允许我们将当前迭代器变为不同类型的迭代器。Other methods defined on the Iterator trait, known as iterator adaptors, allow us to change iterators into different kind of iterators. In"和"notin"操作也支持迭代器:如果能够在迭代器iterator 返回的数据流中找到X的话,则''Xiniterator ''为真。 The"in" and"not in" operators also support iterators: X in iterator is true if X is found in the stream returned by the iterator . For first in iterator . 我们首先假设Iterator需要是一个forwarditerator 。 Suppose forwardIterator is a forward iterator . We can also do this using the same iterator . Iteratorit=collection.iterator ();//获得一个迭代子. For Iterator it= collection. iterator (); it. 相反它必须由IteratorAggregate或Iterator 接口实现。 Instead it must be implemented by either IteratorAggregate or Iterator . Iterator interface has three methods.Iterator property and thus are iterable.Iterator property to create your own iterables.相比Iterator ,我更喜欢Generator。 That is why I prefer Easygenerator.必须返回asynchronousiterator 从其__aiter__()方法。 Must return an asynchronous iterator from its__aiter__() method. 这五个迭代器约束是:OutputIterator,InputIterator,ForwardIterator,BidirectionalIterator和RandomAccessIterator 。 The five categories of iterators are: input, output, forward, bidirectional, and random access iterator . 更多信息,请参考PDF文档SCARYIterator AssignmentandInitialization。 For more information, see the PDF document SCARY Iterator Assignment and Initialization. 用术语来说,就是reverse的参数要是BidirectionalIterator 而非. In terms of concepts, we say that reverse's arguments must be models of Bidirectional Iterator rather than Input Iterator. .
Display more examples
Results: 124 ,
Time: 0.017