Using int vs Integer

后端 未结 9 1486
抹茶落季
抹茶落季 2020-12-01 01:28

I came across a class using Integer variables to capture size to be used in a for loop. Is this good practice or should we use the int primitive data type?

I         


        
9条回答
  •  心在旅途
    2020-12-01 01:39

    There can be a performance penalty due to boxing and unboxing, as you incur the overhead of converting between a primitive and a reference type.

    However, the Integer class adds additional methods that can be very useful.

提交回复
热议问题