Long vs Integer, long vs int, what to use and when?

前端 未结 7 768
醉梦人生
醉梦人生 2020-12-12 12:14

Sometimes I see API\'s using long or Long or int or Integer, and I can\'t figure how the decision is made for that?

7条回答
  •  孤街浪徒
    2020-12-12 12:58

    • By default use an int, when holding numbers.
    • If the range of int is too small, use a long
    • If the range of long is too small, use BigInteger
    • If you need to handle your numbers as object (for example when putting them into a Collection, handling null, ...) use Integer/Long instead

提交回复
热议问题