匹配有人可以让我知道如果某些条件matches.I现在用的并行流如何从forEach循环退出如何从的forEach退出。如果某些条件的Java 8
以下是我的代码。
Map<int[], String[]> indexAndColNamePairs = depMapEntry.getKey();
Set<List<String>> dataRecords = depMapEntry.getValue();
for(Map.Entry<int[], String[]> indexAndColNamePair: indexAndColNamePairs.entrySet())
{
int refColIndex = indexAndColNamePair.getKey()[0];
Stream<List<String>> dataRecs = dataRecords.parallelStream();
dataRecs.forEach((row) -> {
if(referencingValue.equals(row.get(refColIndex)))
{
requiredColValueAndName.put(row.get(indexAndColNamePair.getKey()[1]),
indexAndColNamePair.getValue()[1]);
}
});
if(referencingValue.equals(row.get(refColIndex)))
然后我插入值映射,然后我需要退出。
在if块的末尾添加'break;'命令应该可以做到。 –
我不想从循环中断,我想从forEach中断。也不可能在if块中使用break或continue。 – user3743797
对于每个仍然是for循环,只是它的一个不同的实现。中断应该仍然工作 –