Java2all.com  

Integer





Share This Topic -

Integer class :

The Integer class encapsulates an integer value. This class provides following constructors:

Integer(int i)

Integer(String str)

Here, i is a simple int value and str is a String object. 

EX :

 import java.util.*;
public class Int_Demo
{
    public static void main(String args[])
    {
        Integer i1 = new Integer(12);
        System.out.println("I1 = " + i1);
        System.out.println("Binary Equivalent = " + Integer.toBinaryString(i1));
        System.out.println("Hexadecimal Equivalent = " + Integer.toHexString(i1));
        System.out.println("Minimum Value of Integer = " + Integer.MIN_VALUE);
        System.out.println("Maximum Value of Integer = " + Integer.MAX_VALUE);
        System.out.println("Byte Value of Integer = " + i1.byteValue());
        System.out.println("Double Value of Integer = " + i1.doubleValue());
        Integer i2 = new Integer(12);
        System.out.println("i1==i2 " + i1.equals(i2));
        System.out.println("i1.compareTo(i2) = " + i2.compareTo(i1));
        // Compareto - if it is less than it returns -1 else 1, if equal it return 0.
        Integer i3 = Integer.valueOf("11", 16);
        System.out.println("i3 = " + i3);
    }
}

 
Output :
 
I1 = 12
Binary Equivalent = 1100
Hexadecimal Equivalent = c
Minimum Value of Integer = -2147483648
Maximum Value of Integer = 2147483647
Byte Value of Integer = 12
Double Value of Integer = 12.0
i1==i2 true
i1.compareTo(i2) = 0
i3 = 17