95
Java Byte decode() method
The decode() method of Java Byte class decodes a String into a Byte. It can accept decimal, hexadecimal and octal numbers.
Syntax:
Parameters:
The parameter ‘nm’ represents the String to decode.
Throws:
The decode() method throws :
NumberFormatException- if the String does not contains a parsable byte.
Return Value
This method returns a Byte object holding the byte value of string ‘nm’.
Example 1
Output:
12
Example 2
Output:
Exception in thread "main" java.lang.NumberFormatException: For input string: "null" at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) at java.lang.Integer.parseInt(Integer.java:580) at java.lang.Integer.valueOf(Integer.java:740) at java.lang.Integer.decode(Integer.java:1197) at java.lang.Byte.decode(Byte.java:277) at com.TutorAspire.JavaByteDecodeExample2.main(JavaByteDecodeExample2.java:6)
Example 3
Output:
Exception in thread "main" java.lang.NumberFormatException: For input string: "Byte.MIN_VALUE" at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) at java.lang.Integer.parseInt(Integer.java:580) at java.lang.Integer.valueOf(Integer.java:740) at java.lang.Integer.decode(Integer.java:1197) at java.lang.Byte.decode(Byte.java:277) at com.TutorAspire.JavaByteDecodeExample3.main(JavaByteDecodeExample3.java:7)
Next TopicJava Byte