在 Java 中將字串轉換為位元組數字


使用 Java 中的 parseByte() 方法將字串轉換為位元組。

假設我們的字串如下:

String str = “76”;

現在,parseByte() 方法將此字串轉換為位元組:

byte val = Byte.parseByte(str);

以下是一個示例:

示例

 線上演示

public class Demo {
    public static void main(String[] args) throws Exception {
       String str = "76";
       byte val = Byte.parseByte(str);
       System.out.println(val);
    }
}

輸出

76

更新時間:2020 年 6 月 26 日

180 次瀏覽

開啟您的 職業生涯

完成此課程以獲得認證

開始
廣告
© . All rights reserved.