-1
我正在遍历使用迭代器类型为Abc的allRecords列表。为了跟踪迭代的元素 ,我保持一个位置变量。在Java中使用Lambda返回Arraylist中的元素的位置
我使用这个位置变量来进一步在我的程序中应用一些逻辑。
代码片段如下:
Abc abc;
Iterator<Abc> iterator = allRecords.iterator();
while (iterator.hasNext()) {
abc = iterator.next();
position++;
//validate the abc object with some conditions and break the loop if matches
//I will have that position where the condition matched
}
我的问题是,我可以使用一些Java的最新流API或lambda表达式来完成这项任务。
任何帮助,将不胜感激。
流的点将避免像索引的东西,你想在这里实现什么? – Rogue