利用List删除数据有错,怎么解决啊?
程序代码:
import com.etc.entity.Staff; public class DeleteStaff { private static List<Staff> staffList = new ArrayList<Staff>(); public void deleteSatff(String num) { InsertStaff insertStaff = new InsertStaff(); staffList = insertStaff.getList(); for (Staff s : staffList) { if (s.getNum().equals(num)) { staffList.remove(s); } System.out.println("员工" + s.getName() + "已删除"); } } } //这是Staff public class Staff { private String num; private String name; private String salary; public Staff() { super(); // TODO Auto-generated constructor stub } public Staff(String num, String name, String salary) { super(); this.num = num; this.name = name; this.salary = salary; } @Override public String toString() { return "Staff [num=" + num + ", name=" + name + ", salary=" + salary + "]"; } public String getNum() { return num; } public void setNum(String num) { this.num = num; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getSalary() { return salary; } public void setSalary(String salary) { this.salary = salary; } }
错误在哪?
我在其他类中调用这个函数,传入一个参数num,删除有num是那一行数据,但是错误的,没删掉,哪错了