- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Convert long primitive to Long object in Java
To convert long primitive to Long object, follow the below steps.
Let’s say the following is our long primitive.
// primitive long val = 45; System.out.println("long primitive: "+val);
Now, to convert it to Long object is not a tiresome task. Include the same long value while creating a new Long object −
// object Long myObj = new Long(val); System.out.println("Long object: "+myObj);
The following is the complete example −
Example
public class Demo { public static void main(String[] args) { // primitive long val = 45; System.out.println("long primitive: "+val); // object Long myObj = new Long(val); System.out.println("Long object: "+myObj); } }
Output
long primitive: 45 Long object: 45
- Related Articles
- Convert Long to numeric primitive data types in Java
- How to convert Long array list to long array in Java?
- Convert String to Long in Java
- Convert from String to long in Java
- Convert Java Boolean Primitive to Boolean object
- Convert Long into String using toString() method of Long class in java
- Convert short primitive type to Short object in Java
- Convert byte primitive type to Byte object in Java
- Convert double primitive type to a Double object in Java
- Convert Decimal to Int64 (long) in C#
- How to convert String to Long in Kotlin?
- C# program to convert string to long
- C++ Program to Convert long Type Variables to int
- C++ Program to Convert int Type Variables to long
- Golang Program to convert long type variables to int

Advertisements