- Java.lang 包類
- Java.lang - 首頁
- Java.lang - Boolean
- Java.lang - Byte
- Java.lang - Character
- Java.lang - Character.Subset
- Java.lang - Character.UnicodeBlock
- Java.lang - Class
- Java.lang - ClassLoader
- Java.lang - Compiler
- Java.lang - Double
- Java.lang - Enum
- Java.lang - Float
- Java.lang - InheritableThreadLocal
- Java.lang - Integer
- Java.lang - Long
- Java.lang - Math
- Java.lang - Number
- Java.lang - Object
- Java.lang - Package
- Java.lang - Process
- Java.lang - ProcessBuilder
- Java.lang - Runtime
- Java.lang - RuntimePermission
- Java.lang - SecurityManager
- Java.lang - Short
- Java.lang - StackTraceElement
- Java.lang - StrictMath
- Java.lang - String
- Java.lang - StringBuffer
- Java.lang - StringBuilder
- Java.lang - System
- Java.lang - Thread
- Java.lang - ThreadGroup
- Java.lang - ThreadLocal
- Java.lang - Throwable
- Java.lang - Void
- Java.lang 包額外內容
- Java.lang - 介面
- Java.lang - 錯誤
- Java.lang - 異常
- Java.lang 包有用資源
- Java.lang - 有用資源
- Java.lang - 討論
Java - Byte byteValue() 方法
描述
Java Byte byteValue() 方法返回此 Byte 的值作為 byte。
宣告
以下是 java.lang.Byte.byteValue() 方法的宣告
public byte byteValue()
重寫
Number 類中的 byteValue
引數
無
返回值
此方法在轉換為 byte 型別後返回此物件表示的數值。
異常
無
使用 new 運算子建立的 Byte 物件獲取 Byte 值示例
以下示例演示了使用 new 運算子建立的 Byte 物件的 Byte byteValue() 方法的使用。我們建立一個 Byte 變數,併為其賦值一個使用 new 運算子建立的 Byte 物件。然後建立一個 byte 變數,並使用 byteValue() 方法為其賦值,最後列印結果。
package com.tutorialspoint;
public class ByteDemo {
public static void main(String[] args) {
// create a Byte object b
Byte b;
// assign value to b
b = new Byte("100");
// create a byte primitive bt
byte bt;
// assign primitive value of b to bt
bt = b.byteValue();
String str = "Primitive byte value of Byte object " + b + " is " + bt;
// print bt value
System.out.println( str );
}
}
輸出
讓我們編譯並執行上述程式,這將產生以下結果:
Primitive byte value of Byte object 100 is 100
使用 valueOf(String) 方法建立的 Byte 物件獲取 Byte 值示例
以下示例演示了使用 valueOf(String) 方法建立的 Byte 物件的 Byte byteValue() 方法的使用。我們建立一個 Byte 變數,併為其賦值一個使用 valueOf(String) 方法建立的 Byte 物件。然後建立一個 byte 變數,並使用 byteValue() 方法為其賦值,最後列印結果。
package com.tutorialspoint;
public class ByteDemo {
public static void main(String[] args) {
// create a Byte object b
Byte b;
// assign value to b
b = Byte.valueOf("100");
// create a byte primitive bt
byte bt;
// assign primitive value of b to bt
bt = b.byteValue();
String str = "Primitive byte value of Byte object " + b + " is " + bt;
// print bt value
System.out.println( str );
}
}
輸出
讓我們編譯並執行上述程式,這將產生以下結果:
Primitive byte value of Byte object 100 is 100
使用 valueOf(byte) 方法建立的 Byte 物件獲取 Byte 值示例
以下示例演示了使用 valueOf(byte) 方法建立的 Byte 物件的 Byte byteValue() 方法的使用。我們建立一個 Byte 變數,併為其賦值一個使用 valueOf(byte) 方法建立的 Byte 物件。然後建立一個 byte 變數,並使用 byteValue() 方法為其賦值,最後列印結果。
package com.tutorialspoint;
public class ByteDemo {
public static void main(String[] args) {
// create a Byte object b
Byte b;
// assign value to b
b = Byte.valueOf((byte) 100);
// create a byte primitive bt
byte bt;
// assign primitive value of b to bt
bt = b.byteValue();
String str = "Primitive byte value of Byte object " + b + " is " + bt;
// print bt value
System.out.println( str );
}
}
輸出
讓我們編譯並執行上述程式,這將產生以下結果:
Primitive byte value of Byte object 100 is 100
java_lang_byte.htm
廣告