Home » Java Byte valueOf() Method

Java Byte valueOf() Method

by Online Tutorials Library

Java Byte valueOf() method

The valueOf() method of Java Byte class returns a byte object holding the specified byte value for the specified String.

The third syntax returns a Byte object which represents the specified String when parsed with the given radix.

Syntax:

Parameters:

x – A byte value

s – The string to be parsed

radix– The radix to be used in interpreting s

Throws

The valueOf() method throws:

NumberFormatException – if the string does not contain a parsable byte.

Return Value

This method returns a byte object holding the value represented by b or by the string or by the string argument in the specified radix.

Example 1

Test it Now

Output:

valueOf() method returns : 8  

Example 2

Test it Now

Output:

valueOf() method returns : 56  

Example 3

Test it Now

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.Byte.parseByte(Byte.java:149)  at java.lang.Byte.valueOf(Byte.java:205)  at java.lang.Byte.valueOf(Byte.java:231)  at com.TutorAspire.JavaByteValueOfExample3.main(JavaByteValueOfExample3.java:7)  

Example 4

Test it Now

Output:

valueOf() method returns : 114  

Next TopicJava Byte

You may also like