- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- 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
Advertisements