Java.lang.Short.decode() Method
Advertisements
Description
The java.lang.Short.decode()method decodes a String into a Short.It accepts decimal, hexadecimal, and octal numbers.
Declaration
Following is the declaration for java.lang.Short.decode() method
public static Short decode(String nm) throws NumberFormatException
Parameters
rm -- This is the String to decode.
Return Value
This method returns a Short object holding the short value represented by nm.
Exception
NumberFormatException -- if the String does not contain a parsable short.
Example
The following example shows the usage of java.lang.Short.decode() method.
package com.tutorialspoint;
import java.lang.*;
public class ShortDemo {
public static void main(String[] args) {
String str = "150";
// returns decoded value of a String into a Short.
Short svalue = Short.decode(str);
// printing decoded value
System.out.println("Decoded value = " + svalue);
}
}
Let us compile and run the above program, this will produce the following result:
Decoded value = 150