Long VS Integer

Long is the Object form of long, and Integer is the object form of int.

Integer is a signed 32 bit integer type

  1. Denoted as Int
  2. Size = 32 bits (4byte)
  3. Can hold integers of range -2,147,483,648 to 2,147,483,647
  4. default value is 0

Long is a signed 64 bit integer type

  1. Denoted as Long
  2. Size = 64 bits (8byte)
  3. Can hold integers of range -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
  4. default value is 0L
  • 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

Leave a Reply