gpt4 book ai didi

java - 如何在 Java 8 中将 continue 放入 forEach 循环中

转载 作者:塔克拉玛干 更新时间:2023-11-03 03:06:07 24 4
gpt4 key购买 nike

<分区>

如何在 java 8 中的 forEach 循环中编写 continue 语句。

List<Integer> numList = Arrays.asList(10,21,31,40,59,60);
numList.forEach(x->{
if(x%2==0){
continue;
}
System.out.println(x);
});

上面的代码给出编译时间错误说在循环外继续

List<Integer> numList = Arrays.asList(10,21,31,40,59,60);
LOOP:numList.forEach(x->{
if(x%2==0){
continue LOOP;
}
System.out.println(x);
});

上面的代码给出了编译时错误说 Undefined Label:LOOP

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com