Wrapper Class - Converting number object to primitive number in Java


A Wrapper class is a class whose object wraps or contains primitive data types. When we create an object to a wrapper class, it contains a field and in this field, we can store primitive data types. In other words, we can wrap a primitive value into a wrapper class object.

Source Code

public class wrapperClass2 {
    public static void main(String args[])
    {
        //Converting number object to primitive number.
 
       // Byte B= new Byte((byte) 65);
        Byte B= Byte.valueOf((byte) 65);
        byte b= B.byteValue();
        System.out.println(b);
 
        // Short S= new Short((short) 25);
        Short S= Short.valueOf((short) 25);
        short s= S.shortValue();
        System.out.println(s);
 
        // Integer I= new Integer((int) 45);
        Integer I= Integer.valueOf((int) 45);
        int i= I.intValue();
        System.out.println(i);
 
        // Float F= new Float(45.25f);
        Float F= Float.valueOf(45.25f);
        float f= F.floatValue();
        System.out.println(f);
 
        Long L= Long.valueOf(1052695);
        long l= L.longValue();
        System.out.println(l);
 
        Double D= Double.valueOf(45.25);
        double d= D.doubleValue();
        System.out.println(d);
 
    }
}
 

Output

65
25
45
45.25
1052695
45.25
To download raw file Click Here

Basic Programs