Home Tutorial Java Corejava Dataconversion String Conversion from String to long

 
 

Share on Google+Share on Google+
Conversion from String to long
Posted on: September 3, 2010 at 12:00 AM
Advertisement
In this tutorial we will learn how to convert a string type data to long type data.

Conversion from String to long:

In this tutorial we will learn how to convert a string type data to long type data.

Description:

This program will take a String value from mystring variable. The line long mylong = Long.parseLong(mystring); converts the mystring string type value to mylong long type value. The parseLong() method coverts the any type data to long type data.

Code:

class Stringtolong {
	public static void main(String[] args) {
		try {
			String mystring = "123456789";
			long mylong = Long.parseLong(mystring);
			System.out.println("Converted value from String to long is: "
					+ mylong);
		} catch (Exception e) {
			System.out.println(" Error " + e);
		}
	}
};
 

Output:

Download this code

Advertisement

Related Tags for Conversion from String to long:


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: September 3, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com