79
Java Byte parseByte() method
The parseByte() method of Java Byte class parses the string argument as a signed decimal. All the characters in the String should be decimal digits, except the first character which can be an ASCII minus or plus sign.
The second parameter parses the specified string argument as a signed byte in the specified radix.
Syntax:
Parameters:
The parameters ‘s’ and ‘radix’ represent the string to be parsed and the radix to be used while parsing s.
Throws
The parseByte() method throws:
NumberFormatException– if the string does not contain a parsable byte.
Return Value
This method returns the byte value represented by the argument in decimal.
Example 1
Output:
-8
Example 2
Output:
Exception in thread "main" java.lang.NumberFormatException: radix 0 less than Character.MIN_RADIX at java.lang.Integer.parseInt(Integer.java:546) at java.lang.Byte.parseByte(Byte.java:149) at com.TutorAspire.JavaByteParseByteExample2.main(JavaByteParseByteExample2.java:8)
Example 3
Output:
113
Example 4
Output:
36 Exception in thread "main" java.lang.NumberFormatException: Value out of range. Value:"null" Radix:36 at java.lang.Byte.parseByte(Byte.java:151) at com.TutorAspire.JavaByteParseByteExample4.main(JavaByteParseByteExample4.java:8)
Next TopicJava Byte