Java Program to Convert Wrapper Objects to Primitive Types

In the previous article we have discussed Java Program to Convert Primitive Types to Wrapper Objects

In this article we will see how to convert Wrapper Objects to Primitive Types.

Program to Convert Wrapper Objects to Primitive Types.

We have created variables of primitive types & we have used the valueOf() method of the Wrapper class  to convert the primitive types to the objects.

Beginners and experienced programmers can rely on these Best Java Programs Examples and code various basic and complex logics in the Java programming language with ease.

Approach:

  1. Declare the primitive type data type of integer , double , Boolean  in variable ob1,ob2,ob3 respectively
  2. Convert the variable to its wrapper objects & store it to a variable .
  3. Display the results .

Program :

public class Main

{
    public static void main(String[] args)
    {
    
        // creating primitive types variables
        int a = 23;
        double b = 23.433;
        boolean c = false;
        
        //converting into wrapper objects
        Integer ob1 = Integer.valueOf(a);
        Double ob2 = Double.valueOf(b);
        Boolean ob3 = Boolean.valueOf(c);
        
        // checks if objects are created or not ..
        if(ob1 instanceof Integer)
        System.out.println("object of Integer created....");
        if(ob2 instanceof Double)
        System.out.println("object of Double created....");
        if(ob3 instanceof Boolean)
        System.out.println("object of Boolean created....");
    }

}
Output :

object of Integer created....
object of Double created....
object of Boolean created....

Explore complete java concepts from the Java programming examples and get ready to become a good programmer and crack the java software developer interview with ease.

Related Java Program: