Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 String to Long in Java
To convert String to Long, use the valueOf() method.
Let’s say the following is our string.
// string
String myStr = "5";
System.out.println("String: "+myStr);
To convert it to Long, we have used valueOf() −
Long longObj = Long.valueOf(myStr);
The following is the complete example to convert a String value to Long −
Example
public class Demo {
public static void main(String[] args) {
// string
String myStr = "5";
System.out.println("String: "+myStr);
// long
Long longObj = Long.valueOf(myStr);
System.out.println("Converted to Long: "+longObj);
}
}
Output
String: 5 Converted to Long: 5
Advertisements