Why is int changed to Integer automatically in java?

前端 未结 6 1563
半阙折子戏
半阙折子戏 2021-01-16 15:12

Why is primitive type int changed to object Integer automatically when i put primitve type int to ArrayList in java?

6条回答
  •  星月不相逢
    2021-01-16 15:42

    ArrayList can only store objects. int is a primitive data type so it is "auto-boxed" to the object equivalent. This only happens as of Java 5, before that you had to box the Integer yourself.

提交回复
热议问题