T remove(int index)
删除一个元素,并将后面的元素向前移动。被删除的元素由返回值返回。
参数:index 被删除的元素位置(必须介于0~size()-1之间) 所有位于index之后的元素都要向前移动一个位置。
类型化与原始数组列表的兼容性 确保不会造成严重的后果后,可以用@SuppressWarnings("unchecked")标注来标记这个变量可以接受类型转换。 @SuppressWarnings("unchecked") ArrayList<Employee> result = (ArrayList<Employee>) employeeDB.find(query);//yields another warning
package arrayList;
import java.util.*;
import equals.Employee;
/**
* This program demonstrates the ArrayList class
* @author Mr.Ding
*@version 1.8.0 2017-11-04
*/
public class ArrayListTest {
public static void main(String[] args){
//fill the staff array list with three Employee objects
ArrayList<Employee> staff = new ArrayList<>();
staff.add(new Employee("Carl Cracker", 75000, 1987, 12, 15));
staff.add(new Employee("Harry Hacker", 50000, 1989, 10, 1));
staff.add(new Employee("Tony Tester", 40000, 1990, 3, 15));
//raise everyone's salary by 5%
for(Employee e : staff){
e.raiseSalary(5);
}
//print out information about all Employee objects
for(Employee e : staff){
System.out.println("name= " + e.getName() + ",salary= " + e.getSalary() + ",hireDay= " + e.getHireDay());
}
}
}