Javatpoint Logo
Javatpoint Logo

Java Short decode() Method

The decode() method of Java Short class is used to decode a string into Short. It accepts decimal, hexadecimal and octal numbers. If we put other than this in string then this method will throw Exception.

Syntax

Parameters

X: An encoded String which will be decoded into Short.

Exception

If input argument "String x" does not contain parsable short then it will throw following exception: throws NumberFormatException

Return value

The decode() method will return Short object that holds short value represented by X.

Example 1: (Decimal Number in String input)

Test it Now

Output:

decoded String value in to Short  = 38 

Example 2: (Octal Number in String input)

Test it Now

Output:

decoded String value in to Short  = 8 

Example 3: (Hexa Number in String input)

Test it Now

Output:

decoded String value in to Short  = 15 

Example 4: (Wrong Input, will throw Exception)

Test it Now

Output:

java.lang.NumberFormatException 

Next TopicJava Short





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA