Java Integer

Java Integer


Java Integer: The meaning and difference between int and integer, converting one to another and need of integer when int already existing etc. are discussed clearly with example in Java int vs Integer. It is advised to read this before going further.

Converting String to int (parsing using parseInt())is given in String to int Conversion in Java.

Example on Java Integer. Some more concepts of Integer are discussed here under.

MIN_VALUE and MAX_VALUE are static final variables declared in Java Integer class that prints the minimum and maximum values an Integer object can take.

We cannot do any arithmetic operations on any Java object. But here, i1*i1 prints 100. The reason is i1 is converted back to int with the concept of autoboxing. This works from JDK 1.5 only; earlier versions of JDK up to 1.4 raises compilation error.

For comparison between Java Integer objects (with == and equals()), strings immutability nature concept is used.

String str1 = i1.toString();
String str2 = String.valueOf(i1);

Any object of Java, to convert into String either toString() of Object class or static method valueOf() can be used.

Just like any object of Java, the Java Integer object i1 takes 4 bytes of memory.

Java Integer is a wrapper class.

============================================================
Your one stop destination for all data type conversions

byte TO short int long float double char boolean
short TO byte int long float double char boolean
int TO byte short long float double char boolean
float TO byte short int long double char boolean
double TO byte short int long float char boolean
char TO byte short int long float double boolean
boolean TO byte short int long float double char

String and data type conversions

String TO byte short int long float double char boolean
byte short int long float double char boolean TO String

Leave a Reply

Your email address will not be published. Required fields are marked *