Why is int changed to Integer automatically in java?

前端 未结 6 1554
半阙折子戏
半阙折子戏 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:30

    autoboxing occurs as collections can only hold objects not primitives. If you need an int primitive out you will have to unbox it with intValue() method when you read it out.

提交回复
热议问题