Java中从String到Long的转换

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值