Byte.parseByte() in Java

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

Syntax:

byte java.lang.Byte.parseByte(String s) throws NumberFormatException

This method takes one argument of type String as its parameter. This method parses the string argument as a signed decimal byte. The characters in the string must all be decimal digits, except that the first character may be an ASCII minus sign '-' ('\u005Cu002D') to indicate a negative value or an ASCII plus sign '+'('\u005Cu002B') to indicate a positive value.

Parameters: One parameter is required for this method.

s: a String containing the byte representation to be parsed.

Returns: the byte value represented by the argument in decimal.

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

For Example:

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

Approach

Java

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

        String s = "123";
        System.out.println(Byte.parseByte(s));

    }
}

Output:

123

No comments:

Post a Comment