Integer類longValue()方法
- longValue() 方法可在
java.lang
包。 - longValue() 方法用於返回此 Integer 對象表示的值轉換為 long 類型(通過強製轉換)。
- longValue() 方法是一個非靜態方法,它隻能通過類對象訪問,如果我們嘗試使用類名訪問方法,那麽我們將得到一個錯誤。
- longValue() 方法在從 Integer 轉換為 long 時不會拋出異常。
用法:
public long longValue();
參數:
- 它不接受任何參數。
返回值:
這個方法的返回類型是long
,它返回由此 Integer 對象表示的轉換後的(從 double 類型到 long 類型)值。
例:
// Java program to demonstrate the example
// of longValue() method of Integer class
public class LongValueOfIntegerClass {
public static void main(String[] args) {
// Variables initialization
int i1 = 20;
int i2 = 30;
// It returns integer value denoted by this Integer ob1 object
// and converted to a long by calling ob1.longValue()
Integer ob1 = new Integer(i1);
// Display ob1 result
System.out.println("ob1.longValue():" + ob1.longValue());
// It returns integer value denoted by this Integer ob2 object
// and converted to a long by calling ob2.longValue()
Integer ob2 = new Integer(i2);
// Display ob2 result
System.out.println("ob2.longValue():" + ob2.longValue());
}
}
輸出
ob1.longValue():20 ob2.longValue():30
相關用法
- Java Integer longValue()用法及代碼示例
- Java Integer lowestOneBit()用法及代碼示例
- Java Integer doubleValue()用法及代碼示例
- Java Integer max()用法及代碼示例
- Java Integer intValue()用法及代碼示例
- Java Integer floatValue()用法及代碼示例
- Java Integer toUnsignedLong()用法及代碼示例
- Java Integer parseUnsignedInt()用法及代碼示例
- Java Integer reverseBytes()用法及代碼示例
- Java Integer numberOfLeadingZeros()用法及代碼示例
- Java Integer shortValue()用法及代碼示例
- Java Integer compare()用法及代碼示例
- Java Integer byteValue()用法及代碼示例
- Java Integer min()用法及代碼示例
- Java Integer getInteger()用法及代碼示例
- Java Integer reverseBytes(int i)用法及代碼示例
- Java Integer toUnsignedString()用法及代碼示例
- Java Integer compareTo()用法及代碼示例
- Java Integer numberOfTrailingZeros()用法及代碼示例
- Java Integer remainderUnsigned()用法及代碼示例
注:本文由純淨天空篩選整理自Preeti Jain大神的英文原創作品 Java Integer class longValue() method with example。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。