Java Long类parseLong()方法与示例

Syntax:

句法:

    public static long parseLong(String str);
    public static long parseLong(String str, int radix's);

长类parseLong()方法 (Long class parseLong() method)

  • parseLong() method is available in java.lang package.

    parseLong()方法在java.lang包中可用。

  • parseLong(String str) method is used to return the long value corresponding to the given String denotation or in other words we can say this method is used to convert string value to a long value.

    parseLong(String str)方法用于返回与给定String表示形式相对应的long值,换句话说,我们可以说此方法用于将字符串值转换为long值。

  • parseLong (String str, int radix's) method is used to return the long value corresponding to the given String denotation as a signed long in the radix's given by the second argument.

    parseLong(String str,int radix's)方法用于返回与给定String表示形式相对应的long值,作为第二个参数给定的基数中的有符号long。

  • parseLong (String str), parseLong (String str, int radix's) method may throw a NumberFormatException at the time of conversion from String to long.

    从String转换为long时, parseLong(String str)parseLong(String str,int radix's)方法可能会引发NumberFormatException。

    NumberFormatException: In this exception, if String does not contain the parsable number.

    NumberFormatException :在此异常中,如果String不包含可分析的数字。

  • These are static methods, they are accessible with the class name too and, if we try to access these methods with the class object then also we will not get an error.

    这些是静态方法,它们也可以使用类名进行访问,并且,如果我们尝试使用类对象访问这些方法,那么也不会出错。

Parameter(s):

参数:

  • In the first case, String value – represents the value of String type.

    在第一种情况下, 字符串值 –表示字符串类型的值。

  • In the second case, String value, int radix'svalue represents the value of String type in the radix's given by the second parameter.

    在第二种情况下, 字符串值,即int radix的 – 值表示第二个参数给定的基数中的 String类型的值。

Return value:

返回值:

In the first case, the return type of this method is long - it returns the Long representation of this String argument.

在第一种情况下,此方法的返回类型为long-它返回此String参数的Long表示形式。

In the second case, the return type of this method is long - it returns the Long representation of the String argument in the radix's given by the second argument.

在第二种情况下,该方法的返回类型是长 -它返回的基数的字符串参数的龙表示年代由第二个参数给出。

Example:

例:

// Java program to demonstrate the example 
// of parseLong() method of Long class

public class ParseShortOfLongClass {
    public static void main(String[] args) {
        // Variables initialization
        String str1 = "100";
        String str2 = "67";
        int radix = 20;

        // Object initialization
        Long l1 = new Long(str2);

        // It convert string into long by calling parseLong(str1) method
        // and store the result in another variable of long type
        long result = l1.parseLong(str1);

        // Display result
        System.out.println("l1.parseLong(str1): " + result);

        // It convert string into long with radix 20 by 
        // calling parseLong(str1,radix's) method
        // and store the result in a variable of long type
        result = l1.parseLong(str1, radix);

        // Display result
        System.out.println("l1.parseLong(str1,radix): " + result);
    }
}

Output

输出量

l1.parseLong(str1): 100
l1.parseLong(str1,radix): 400


翻译自: https://www.includehelp.com/java/long-class-parselong-method-with-example.aspx

  • 4
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值