我正在使用 foreach 循环遍历 arraylist 并将名称与字符串进行比较。但我不知道为什么当我将名称与字符串进行比较时,它总是会打印出来。
for (Picture item : collection) {
System.out.println("This is the label " + item.getName());
if (item.getName().equals("This shouldn't work")); {
System.out.println("Why is this working");
}
}
}
输出
getting the name test A
This is the label A
getting the name test A
Why is this working
getting the name test B
This is the label B
getting the name test B
Why is this working