Java Short parseShort() method

The parseShort() method of Java Short class is used to parse the string argument as a signed decimal short.

Syntax

Parameters

x: A String containing the short representation to be parsed. The all characters in the string must be in decimal digits.

Return value

It returns short value represented by the argument in decimal.

Exception

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

Example 1

Output:

String 100 , parse value into parseShort  =100

Example 2

Output:

String -500 , parse value into parseShort  =-500

Example 3

Output:

NumberFormatException

Screenshort:

ShortParseShort

Java Short parseShort(String x, int radix) method

The parseShort(String x, int radix ) method of java Short class is used to parse the string argument as a signed short in the radix specified by the second argument.

Syntax

Parameters

x:A string containing the short to be parsed.

radix: radix to be used while parsing string contain short value.

Return value

It return short represented by the string argument in the specified radix.

Exception

It throws NumberFormatException if:

  • The first argument is null or is a string of length zero
  • Any character of the string is not a digit.
  • The radix is either smaller than Character.MIN_RADIX or larger than Character.MAX_RADIX
  • The value represented by the string is not a value of type short

Example 4

Output:

String 100 parsed specified by radix  2  , into signed decimal short = 4

Example 5

Output:

NumberFormatException

Screenshort:

ShortParseShort

Example 6

String length is Zero

Output:

NumberFormatException

Screenshort:

ShortParseShort

Example 7

Output:

String  parsed specified by radix  into signed decimal short = 35