String To long In Java
Chapter:
String Handling
Last Updated:
13-08-2016 13:27:05 UTC
Program:
/* ............... START ............... */
public class JavaStringToLong {
public static void main(String[] args) {
String str = "38399383";
// Conversion using parseInt method
long num = Long.parseLong(str);
// Conversion using valueOf method
long num2 = Long.valueOf(str);
// Conversion: Long(String s) constructor
long num3 = new Long(str);
// Displaying variables values
System.out.println(num);
System.out.println(num2);
System.out.println(num3);
}
}
/* ............... END ............... */
Output
38399383
38399383
38399383
Notes:
-
The Long.parseLong() static method parses the string argument as a signed decimal long and returns a long value.
- Syntax : public static long parseLong(String s) throws NumberFormatException.
- The Long.valueOf() static method will return an Long object holding the value of the specified String.
- Syntax : public static Long valueOf(String s) throws NumberFormatException.
Tags
String To long, Java, Stringc