我正在使用foreach循環來運行arraylist並將名稱與字符串進行比較。但是我不知道爲什麼當我比較一個字符串的名字時總會打印出來。嘗試按名稱調用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
你的'if'條件後面有一個懸掛';'。 –
@SotiriosDelimanolis常見的分號用法/非用法問題。 –
還有那個'呃'的臉掌...快速調查,你輸了多少個小時,@pplll,你會再次這樣做嗎? (哦,對我來說,它是大約2,並且再也沒有這樣做過)...... – rolfl