我正在做一项任务,我们必须使用数组列表来创建一个存储员工信息的应用程序(工资,姓名,ID#,开始日期)。我们被告知要为员工的记录创建一个班级。我必须让程序从员工ID#中删除整个条目,我很难搞清楚。
//removes entries from record using only ID
String id;
int i;
id = idIn.getText();
下面的是创建类
的代码 //class for employees
class employees{
String first, last, id, date, salary;
employees (String _first, String _last, String _id, String _date, String _salary){
first = _first;
last = _last;
id = _id;
date = _date;
salary = _salary;
}
}
System.out.println(id);
i = records.indexOf(id);
System.out.println(i);
这是数组列表的创建
//create array for records
ArrayList <employees> records = new ArrayList <employees>();
这就是条目被添加到列表中的方式
//add records to array
employees e;
String first, last, id, date, salary;
first = firstIn.getText();
last = lastIn.getText();
id = idIn.getText();
date = dateIn.getText();
salary = salaryIn.getText();
e = new employees (first, last, id, date, salary);
records.add(e);
在搜索ID#
的索引时,我得到的值为-1