public static void deleteEmployee(int empId) {
Iterator<Employee> iterator = list1.iterator();
while (iterator.hasNext()) {
if (iterator.next().getEmpid() == empId) {
System.out.println("The name of whose details deleted is ::");
iterator.remove();
}
}
}
这里我试图根据员工ID从arraylist中删除节点。但在删除之前我想显示特定员工的详细信息。我怎么能这样做?
答案 0 :(得分:4)
如何将员工存储在临时变量中?
public static void deleteEmployee(int empId) {
Iterator<Employee> iterator = list1.iterator();
while (iterator.hasNext()) {
Employee employee = iterator.next();
if (employee.getEmpid() == empId) {
System.out.println("The name of whose details deleted is ::" + employee.getName()); // or whatever property in employee
iterator.remove();
}
}
}
答案 1 :(得分:0)
这与Iterator
或List
无关。
查看Employee
:是否有toString()
实施打印详细信息?如果没有,它的属性是否有吸气剂?与System.out.println
一起使用。