首页 > 编程知识 正文

Java Long类的valueOf方法及示例,java调用其他类的方法

时间:2023-05-06 20:11:24 阅读:247252 作者:4547

Syntax:

句法:

public static Long valueOf (long value); public static Long valueOf (String value); public static Long valueOf (String value, int radix's); 长类valueOf()方法 (Long class valueOf() method)

valueOf() method is available in java.lang package.

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

valueOf (long value) method is used to represent a Long object denoted by the given argument (value) is of long type.

valueOf(长值)方法用于表示由给定参数(值)表示的Long对象是long类型。

valueOf (String value) method is used to represent a Long object holding the long value denoted by the given argument (value) is of String type.

valueOf(字符串值)方法用于表示一个Long对象,该对象持有由给定参数(值)表示的long值是String类型。

valueOf (String value, int radix's) method is used to represent a Long object holding the long value of the given argument (value) in the radix's given by the second argument.

valueOf(String value,int radix's)方法用于表示一个Long对象,该对象持有第二个参数给定的基数中给定参数(值)的long值。

valueOf (long value) method does not throw an exception at the time of returning a Long instance.

返回Long实例时, valueOf(长值)方法不会引发异常。

Similarly, valueOf (String value), valueOf (String value, int radix's) method may throw a NumberFormatException at the time of returning an instance.

同样,在返回实例时, valueOf(String value) , valueOf(String value,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, long value – represents the value of long type.

在第一种情况下, long value –表示long类型的值。

In the second case, String value – represents the value of String type.

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

In the third case, String value, int radix's – value 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 long argument.

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

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

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

In the third 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.

在第三种情况下,此方法的返回类型为Long-它返回第二个参数给定的基数中String参数的Long表示形式。

Example:

例:

// Java program to demonstrate the example // of valueOf() method of Long classpublic class ValueOfLongClass { public static void main(String[] args) { // Object initialization Long ob1 = new Long(100); Long ob2 = new Long(200); Long ob3 = new Long(40); // Display ob1,ob2,ob3 values System.out.println("ob1: " + ob1); System.out.println("ob2: " + ob2); System.out.println("ob3: " + ob3); // It returns Long object holding the value // denoted by the given long argument Long value1 = ob1.valueOf(20); // String object initialization for valueOf(String s) String s = "80"; // It returns Long object holding the value // denoted by the given String argument Long value2 = ob2.valueOf(s); // It returns Long object holding the value // denoted by the given String argument with radix 20 Long value3 = ob3.valueOf(s, 20); // Display result values System.out.println("ob1.valueOf(20): " + value1); System.out.println("ob2.valueOf(s): " + value2); System.out.println("ob3.valueOf(s,20): " + value3); }}

Output

输出量

ob1: 100ob2: 200ob3: 40ob1.valueOf(20): 20ob2.valueOf(s): 80ob3.valueOf(s,20): 160

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

win7电脑文件夹如何加密

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。