- Trending Categories
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 from String to long in Java
To convert String to long, the following are the two methods.
Method 1
The following is an example wherein we use parseLong() method.
Example
public class Demo { public static void main(String[] args) { String myStr = "5"; Long myLong = Long.parseLong(myStr); System.out.println("Long: "+myLong); } }
Output
Long: 5
Method 2
The following is an example wherein we have used valueOf() and longValue() method to convert String to long.
Example
public class Demo { public static void main(String[] args) { String myStr = "20"; long res = Long.valueOf(myStr).longValue(); System.out.println("Long: "+res); } }
Output
Long: 20
- Related Articles
- Convert String to Long in Java
- Convert Long into String using toString() method of Long class in java
- Convert from float to String in Java
- Convert from String to float in Java
- Convert long primitive to Long object in Java
- How to convert String to Long in Kotlin?
- C# program to convert string to long
- How to convert Long array list to long array in Java?
- Java Program to convert from integer to String
- Java Program to convert from String to integer
- How to Convert Int to Long in Java?
- Convert Java String to Short in Java
- Convert Long to numeric primitive data types in Java
- Convert double to string in Java
- Convert short to String in Java

Advertisements