Facebook Page Twitter Page LinkedIn Page
× Java.lang Package Classes


The java.lang.Byte.parseByte() method is used to parse 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 '-' ('\u002D') to indicate a negative value or an ASCII plus sign '+' ('\u002B') to indicate a positive value. The resulting byte value is returned, exactly as if the argument and the radix 10 were given as arguments to the parseByte(java.lang.String, int) method.

Syntax

public static byte parseByte(String s)
                      throws NumberFormatException

Parameters

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

Return Value

Returns the byte value represented by the argument in decimal.

Exception

throws NumberFormatException, if the string does not contain a parsable byte.

Example:

In the below example, the java.lang.Byte.parseByte() method is used to parse the string argument as a signed decimal byte.

import java.lang.*;

public class MyClass {
  public static void main(String[] args) {
    
    //creating a string holding byte value
    String x = "25";

    //creating byte value
    byte y = Byte.parseByte(x);

    //printing the string
    System.out.println("The string is: " + x); 

    //printing the byte value
    System.out.println("The byte value is: " + y);   
  }
}

The output of the above code will be:

The string is: 25
The byte value is: 25

❮ Java.lang - Byte