【发布时间】:2018-01-27 23:32:17
【问题描述】:
我正在使用迭代器遍历我的 abc 类型的 allRecords 列表。跟踪元素 迭代,我保留一个位置变量。
我使用这个位置变量在我的程序中进一步应用一些逻辑。
代码sn-p如下:
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 表达式来完成这项任务吗?
任何帮助将不胜感激。
【问题讨论】:
-
流的重点是避免索引之类的东西,你想在这里实现什么?
标签: java lambda collections