for循环在下面java代码停止在第一次迭代中,我不知道为什么!你能帮助我吗?
controllerSwitches元素是{1,2}
allSwithces元素是{1,2,3,4}
for (int p = 0; p < controllerSwitches.length; p++)
{
switches tempSwitch = controllerSwitches[p];
for (int w = 0; w <= allSwithces.size(); w++)
{
System.out.println(tempSwitch.getSwitchId() +"\t" + allSwithces.get(w).getSwitchId());
if (allSwithces.get(w).getSwitchId().equals(tempSwitch.getSwitchId()))
{
failedControllerswitches.add(allSwithces.get(w)); // it is break after getting the first p index
}
continue;
}
continue;
}
Run Code Online (Sandbox Code Playgroud)
它获得第一个p索引并将其与allSwitches列表的所有元素进行比较,然后打破循环.我的意思是它没有进入第二个p指数.输出是
1 1
1 2
1 3
1 4
它不会将controllerSwitches的第二个元素与allSwithces元素进行比较