利用 ArrayList 的 get 函数拿到的 Integer 类型没有进行自动拆箱
public static void main(String[] args) {
ArrayList<Integer>list=new ArrayList<>();
list.add(1);
list.add(1);
System.out.println(list.get(0));
System.out.println(list.get(1));
System.out.println(list.indexOf(0)==list.indexOf(1));//此处比较的是地址
}
//结果:
1
1
false
关于 get 函数
/**
* Returns the element at the specified position in this list.
*
* @param index index of the element to return
* @return the element at the specified position in this list
* @throws IndexOutOfBoundsException {@inheritDoc}
*/
public E get(int index) {
rangeCheck(index);
return elementData(index);
}