利用 ArrayList get 函数拿到的 Integer 类型没有进行自动拆箱

    1. public static void main(String[] args) {
    2. ArrayList<Integer>list=new ArrayList<>();
    3. list.add(1);
    4. list.add(1);
    5. System.out.println(list.get(0));
    6. System.out.println(list.get(1));
    7. System.out.println(list.indexOf(0)==list.indexOf(1));//此处比较的是地址
    8. }
    9. //结果:
    10. 1
    11. 1
    12. 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);
        }