问题
今天做一道题,用到两个指定Integer泛型类型的LinkedList(list1,list2),先取出list1中下标为index1的元素,把这个元素作为list2链表的下标(index2),再删除list2中下标为index2的元素。一开始想的代码是这样的:
list2.remove(list1.get(index1));//index2相当于list1.get(index1)
突然想到,list1.get(index1)的返回值是Integer类型,这样传入list2.remove()的类型就是Integer类型,实际执行的是remove(Object o)方法。
//测试remove(int index)和remove(Object o)方法
LinkedList