list中定义了两种remove
boolean remove(Object obj):用equals方法查看集合中是否包含obj,若存在则将其删除,并返回true,不存在返回false,只会删除第一个元素
Object remove(int index):移除指定index位置的元素,并返回此元素
他们的参数不同
public class ListTest {
@Test
public void ListTest1(){
ArrayList<Integer> iList = new ArrayList<>();
System.out.println(iList.getClass().getName());
iList.add(1);
iList.add(2);
iList.add(3);
//如果参数只写2,那么只会删除索引为2的元素
iList.remove(2);
//要删除元素值为2的元素要new一个包装类
iList.remove(new Integer(2));
}
}