Short類decode()方法
- decode() 方法可在
java.lang
包。 - decode() 方法用於將給定的 String 值解碼為 Byte 值。
- decode() 方法是一個靜態方法,它也可以通過類名訪問,如果我們嘗試使用類對象訪問該方法,那麽我們也不會收到錯誤。
- decode() 方法在將 String 解碼為 Byte.NumberFormatException 時可能會拋出 NumberFormatException:在此異常中,如果給定的字符串參數沒有可解析的字節。
用法:
public static Byte decode(String str);
參數:
String str
– 表示要解碼的字符串。
返回值:
這個方法的返回類型是Byte
,它返回保存由 String 類型的參數表示的字節值的 Byte。
例:
// Java program to demonstrate the example
// of decode(String str) method of Byte class
public class DecodeOfByteClass {
public static void main(String[] args) {
// Variables initialization
byte by = 100;
String str = "20";
// Byte object initialized with "byte" value
Byte value1 = new Byte(by);
// Display value1 result
System.out.println("value1:" + value1);
// It returns an Byte object holding the byte value
// denoted by the given String argument by calling
// value1.decode(str)
Byte result = value1.decode(str);
// Display result
System.out.println("value1.decode(str):" + result);
}
}
輸出
value1:100 value1.decode(str):20
相關用法
- Java Byte decode()用法及代碼示例
- Java Byte doubleValue()用法及代碼示例
- Java Byte valueOf()用法及代碼示例
- Java Byte floatValue()用法及代碼示例
- Java Byte hashCode()用法及代碼示例
- Java Byte compareTo()用法及代碼示例
- Java Byte toString()用法及代碼示例
- Java Byte longValue()用法及代碼示例
- Java Byte compare()用法及代碼示例
- Java Byte equals()用法及代碼示例
- Java Byte byteValue()用法及代碼示例
- Java Byte intValue()用法及代碼示例
- Java Byte shortValue()用法及代碼示例
- Java Byte compareUnsigned()用法及代碼示例
- Java Byte toUnsignedInt()用法及代碼示例
- Java Byte parseByte()用法及代碼示例
- Java Byte toUnsignedLong()用法及代碼示例
- Java ByteArrayInputStream markSupported()用法及代碼示例
- Java ByteBuffer isDirect()用法及代碼示例
- Java ByteBuffer compareTo()用法及代碼示例
注:本文由純淨天空篩選整理自Preeti Jain大神的英文原創作品 Java Byte class decode() method with example。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。