Java Data Type Tutorial - Byte Byte(String s) throws NumberFormatException example








Byte(String s) creates a Byte object to represent the byte value indicated by the String parameter.

The string is converted to a byte value in the same way as parseByte method for radix 10.

Syntax

Byte has the following syntax.

public Byte(String s) throws NumberFormatException

Parameters

Byte has the following parameters.

s
the String value to be converted to a Byte

Throws

Byte throws.

NumberFormatException
If the String does not contain a parsable byte.

Example

In the following code shows how to use Byte.Byte(String s) constructor.

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

    Byte byteObject = new Byte("100");
    System.out.println(byteObject);


  }
}

The output: