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








Byte decode(String nm) decodes a String into a Byte.

Syntax

decode has the following syntax.

public static Byte decode(String nm) throws NumberFormatException

Parameters

decode has the following parameters.

nm
the String to decode.

Return

decode returns a Byte object holding the byte value represented by String

Throws

decode throws.

NumberFormatException
if the String does not contain a parsable byte.

Example

In the following code shows how to use Byte.decode(String nm) method.

The following code use decode method from Byte class to do the decoding for strings which represents the byte values

public class Main {
  public static void main(String[] args) {
    /* w  w  w.j a  v a 2 s  .c o  m*/
    System.out.println("Decimal 10:"+Byte.decode("10"));
    System.out.println("Octal 10:"+Byte.decode("010"));
    System.out.println("Hex F:"+Byte.decode("0XF"));
    
    
    System.out.println("Negative Hex F:"+Byte.decode("-0XF"));
  }
}

The output: