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


This content was proof-read by Grammarly. You can Try Grammary for FREE

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

Newsletter Signup

Subscribe to our weekly newsletter below and never miss the latest product or an exclusive offer.

Newsletter Signup

Subscribe to our weekly newsletter below and never miss the latest product or an exclusive offer.

%d bloggers like this: