Methods to Convert String to Long

There are many methods for converting a String to a Long data type in Java which are as follows:

  1. Using the parseLong() method of the Long class 
  2. Using valueOf() method of long class 
  3. Using the constructor of the Long class

Java Program to Convert String to Long

In this article, we will be performing String to Long Conversion with different methods.

Similar Reads

Illustration of the Conversion String to Long

Input : String = “20”Output : 20 Input : String = “999999999999”Output : 999999999999...

Methods to Convert String to Long

There are many methods for converting a String to a Long data type in Java which are as follows:...

1. Using Long.parseLong() method of Long Class

Long.parseLong() method is a method in which all the characters in the String must be digits except the first character, which can be a digit or a minus ‘-‘....

2. Using valueOf() Method of Long Class

...

3. Using Constructor of Long Class

The valueOf() method of the Long class is a method that converts the String to a long value. Similar to parseLong(String) method, this method also allows minus ‘-‘ as a first character in the String....