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