When adding an integer to ArrayList

后端 未结 3 1907
走了就别回头了
走了就别回头了 2021-01-15 20:50

I have a very stupid question here. When we add an int value to an ArrayList, will it create a new Integer object of that int value? For example:

int a = 1;
         


        
3条回答
  •  情书的邮戳
    2021-01-15 21:26

    The a is autoboxed to an Integer. From the link,

    Autoboxing is the automatic conversion that the Java compiler makes between the primitive types and their corresponding object wrapper classes.

提交回复
热议问题