Java - Integer

> Procedural Languages > Java

1 - About

Number - Integer - <math>\mathbb{Z} </math> in Java

  • int uses a 32 bits word - data range goes from <math>-2^31</math> to <math>+2^{31-1}</math> ( ±2 billion)
  • long uses 64 bits,

2 - From / To

2.1 - From Long

  • for a long object
Long theLong;
Integer i = theLong.intValue()
  • or from a long primitive
Math.toIntExact(long)
Advertising

2.2 - To Long

Long i = theinteger.longValue()