使用迭代器时如何获取当前循环索引?

时间:2023-02-25
本文介绍了使用迭代器时如何获取当前循环索引?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个迭代器来遍历一个集合我想获取当前元素的索引.

I am using an Iterator to iterate through a collection and I want to get the current element's index.

我该怎么做?

推荐答案

使用自己的变量并在循环中递增.

Use your own variable and increment it in the loop.

这篇关于使用迭代器时如何获取当前循环索引?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

上一篇:迭代器 hasext() 返回 true 但 next() 抛出 NoSuchElemen 下一篇:为什么 Java 不允许在迭代器上使用 foreach(仅在可

相关文章

最新文章