Java Long类的valueOf()方法及示例
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(長值)方法不會引發(fā)異常。
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)方法可能會引發(fā)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.
這些是靜態(tài)方法,它們也可以使用類名進行訪問,并且,如果我們嘗試使用類對象訪問這些方法,那么也不會出錯。
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 initializationLong ob1 = new Long(100);Long ob2 = new Long(200);Long ob3 = new Long(40);// Display ob1,ob2,ob3 valuesSystem.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 argumentLong 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 argumentLong value2 = ob2.valueOf(s);// It returns Long object holding the value // denoted by the given String argument with radix 20Long value3 = ob3.valueOf(s, 20);// Display result valuesSystem.out.println("ob1.valueOf(20): " + value1);System.out.println("ob2.valueOf(s): " + value2);System.out.println("ob3.valueOf(s,20): " + value3);} }Output
輸出量
ob1: 100 ob2: 200 ob3: 40 ob1.valueOf(20): 20 ob2.valueOf(s): 80 ob3.valueOf(s,20): 160翻譯自: https://www.includehelp.com/java/long-class-valueof-method-with-example.aspx
總結
以上是生活随笔為你收集整理的Java Long类的valueOf()方法及示例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Java StringBuilder r
- 下一篇: gif 格式 完整 检查_GIF的完整格