Why Integer class caching values in the range -128 to 127?

前端 未结 5 1335
攒了一身酷
攒了一身酷 2020-11-22 08:31

Regarding my previous Question, Why do == comparisons with Integer.valueOf(String) give different results for 127 and 128? , we know that Integer class

5条回答
  •  醉话见心
    2020-11-22 09:10

    When you encounter with Integer class and always boxed within the range -128 to 127 it's always better to convert the Integer object into int value as below.

    .intValue()
    

提交回复
热议问题