Given a string and we have to convert it into a long.
给定一个字符串,我们必须将其转换为long。
Java conversion from String to Long
Java从String转换为Long
To convert a String to Long, we can use the following methods of Long class (see the syntax given below...)
要将String转换为Long ,我们可以使用Long类的以下方法(请参见下面给出的语法...)
Syntax:
句法:
Long Long.valueOf(String).longValue();
OR
Long Long.parseLong(String);
Java代码将字符串转换为Long (Java code to convert a String to Long)
//Java code to convert String to Long
public class Main {
public static void main(String args[]) {
String str = "1234587878";
//variable to store result
long result = 0;
//converting string to long
//method 1
result = Long.valueOf(str).longValue();
System.out.println("result (value of str as long) = " + result);
//method 2
result = Long.parseLong(str);
System.out.println("result (value of str as long) = " + result);
}
}
Output
输出量
result (value of str as long) = 1234587878
result (value of str as long) = 1234587878
翻译自: https://www.includehelp.com/java-programs/conversion-from-string-to-long-in-java.aspx