用Java克隆迭代器 [英] Cloning iterators in Java

查看:324
本文介绍了用Java克隆迭代器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Java中的LinkedList,一个用于浏览列表的迭代器,我想克隆该迭代器以相对于原始迭代器的位置对列表进行一些临时的向前看"处理.

I have a LinkedList in Java, an iterator to browse the list and I would like to clone the iterator to do some temporary "look ahead" processing of the list with respect to the position of the original iterator.

我知道不可能在每种情况下都克隆迭代器,但是有没有办法将迭代器克隆到LinkedList(或保存并恢复其状态)?

I understand that cloning an iterator is not possible in every situation, but is there a way to clone an iterator to a LinkedList (or save and restore its state)?

推荐答案

可能,但是Sun确保不能(通过将类设为私有).

It would be possible but Sun made sure you can't (by making the class private).

但是也许您可以使用listIterator()而不是普通的iterator()来实现所需的功能. ListIterator可以双向移动.

But maybe you can achieve what you want using a listIterator() instead of a plain iterator(). A ListIterator can move in both directions.

这篇关于用Java克隆迭代器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆