提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
您可以传递要删除的实际对象。
import java.util.ArrayList; /* from nowjava - 时代Java*/ public class Main { public static void main(String[] args) { ArrayList<Employee> emps = new ArrayList<Employee>(); // create employee objects Employee emp1 = new Employee("A"); Employee emp2 = new Employee("T"); Employee emp3 = new Employee("K"); // add employee objects to array list emps.add(emp1); emps.add(emp2); emps.add(emp3); // print the array list System.out.println(emps); // 来 自 nowjava.com // remove one of the employees emps.remove(emp2); // print the array list again System.out.println(emps); } } class Employee{ private String name; public Employee(String name) { this.name = name; } public String getName() { return name; } public void setName(