public boolean removeAccount (String accountNumber)
{
int index = 0;
boolean found = false;
while (index < accounts.size() && !found)
{
if (accounts.get(index).getAccountNumber().equals(accountNumber))
{
found = true;
accounts.remove(accountNumber);
}
else
index++;
}
if (found == true)
{
return true;
}
else
return false;
}
當我進入返回true一個正確的帳號,但它不會從ArrayList中刪除帳戶,任何幫助,將不勝感激:)刪除對象(賬戶)
accounts.remove(指數)...由索引位置刪除對象 – fmodos 2014-11-04 19:33:50
注:塊'while'循環可以用'返回找到替代後;'。 – 2014-11-04 19:35:23