Java Byte valueOf() methodThe 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 ThrowsThe valueOf() method throws: NumberFormatException - if the string does not contain a parsable byte. Return ValueThis 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 1Test it NowOutput: valueOf() method returns : 8 Example 2Test it NowOutput: valueOf() method returns : 56 Example 3Test it NowOutput: 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.JavaTpoint.JavaByteValueOfExample3.main(JavaByteValueOfExample3.java:7) Example 4Test it NowOutput: valueOf() method returns : 114 Next TopicJava Byte |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India