Java – How to Convert primitive long datatype to Long object?

Problem Statement

You need to convert the primitive long datatype to object in Java.

Solution

Use the Long wrapper class to convert the long primitive to Long object as shown below.

public class Main {

    public static void main(String[] args) {

        System.out.println("Abundantcode.com Java Tutorials");

        long input1 = 89;

        // Convert primitive long datatype value to Long Object
        Long output = new Long(input1);
        System.out.println(output.longValue());

    }
}

The output of the above program is

Abundantcode.com Java Tutorials

89

Leave Your Comment

Liked this content?. Please spread the word :)