Wrapper Class - Converting primitive number to string object 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 wrapperClass3 {
    public static void main(String args[])
        //Converting primitive number to string object.
        short s=25;
        String S=Short.toString(s);//"25"
        System.out.println("Short String Object : "+S);
        byte b=25;
        String B=Byte.toString(b);
        System.out.println("Byte String Object : "+B);
        int i=25;
        String I=Integer.toString(i);
        System.out.println("Integer String Object : "+I);
        long l=25;
        String L=Long.toString(l);
        System.out.println("Long String Object : "+L);
        float f=25.5f;
        String F=Float.toString(f);
        System.out.println("Float String Object : "+F);
        double d=25.525;
        String D=Double.toString(d);
        System.out.println("Double String Object : "+D);


Short String Object : 25
Byte String Object : 25
Integer String Object : 25
Long String Object : 25
Float String Object : 25.5
Double String Object : 25.525
To download raw file Click Here

Basic Programs