Byte.decode() in Java

Byte.decode(): This method is available in the java.lang.Byte class of Java.

Syntax:

Byte java.lang.Byte.decode(String nm) throws NumberFormatException

This method takes one argument of type String as its parameter. This method decodes a String into a Byte. Accepts decimal, hexadecimal, and octal number.

Parameters: One parameter is required for this method.

nm: the String to decode.

Returns: a Byte object holding the byte value represented by nm.

Throws: NumberFormatException - if the String does not contain a parsable byte.

For Example:

Byte.decode("123") = > It returns 123.

Approach

Java

public class Bytedecode {
    public static void main(String[] args) {

        String nm = "123";
        System.out.println(Byte.decode(nm));

    }
}

Output:

123

No comments:

Post a Comment