All for Joomla All for Webmasters

Java String to long

We can convert String to long in java using Long.parseLong() method.

Scenario

It is generally used if we have to perform mathematical operations on the string that contains long number. Whenever we get data from textfield or textarea, entered data is received as a string. If entered data is long, we need to convert string to long. To do so, we use Long.parseLong() method.

Signature

The parseLong() is the static method of Long class. The signature of parseLong() method is given below:

  1. public static long parseLong(String s)

Java String to long Example

Let’s see the simple code to convert string to long in java.

  1. long l=Long.parseLong(“200”);

Let’s see the simple example of converting String to long in java.

  1. public class StringToLongExample{
  2. public static void main(String args[]){
  3. String s=“1234567890”;
  4. long l=Long.parseLong(s);
  5. System.out.println(l);
  6. }}

Output:

1234567890
PinIt
submit to reddit

Leave a Reply

Top