Latest Tutorials| Questions and Answers|Ask Questions?|Site Map

Home Java Java-conversion Convert String To Long

Related Tutorials


Share on Google+Share on Google+

Convert String To Long

In this section, we are going to convert numeric type string data into long.

Convert String To Long 


In this section, we are going to convert numeric type string data into long. The following program provides a functionality  to convert a string data (integer)  into a long type data. 

Code Description:

This program helps you in converting a string type data into a long. Here, define a class named "StringToLong" for java component. Program takes an integer type data as a string format at the console. And transformed  into a long type data using  the parseLong() method.  


This method is used to convert a string into a long.

Here is the code of this program:

import java.lang.*;

public class  StringToLong{
  public static void main(String[] argsthrows IOException{
  BufferedReader read = 
new BufferedReader(new InputStreamReader(;
  System.out.println("Enter the any string number:");
  String str = read.readLine();
  long l = Long.parseLong(str);
  System.out.println("long:= " + l);
  catch (Exception e){
  System.out.println("Exception: " + e.getMessage());

Download this program:

Output this program.

 C:\corejava>java StringToLong
Enter the any string number:
long:= 50

If you enjoyed this post then why not add us on Google+? Add us to your Circles

Liked it!  Share this Tutorial

Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: July 4, 2007

Related Tutorials

Discuss: Convert String To Long   View All Comments

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image