Java Short.parseShort(String s, int radix) example

By Yashwant Chavan, Views 25, Last updated on 10-Apr-2019

In this java tutorial, You will learn how to use parseShort(String s, int radix) method of Short class. This method, Parses the string argument as a signed short in the radix specified by the second argument. The characters in the string must all be digits, of the specified radix (as determined by whether Character.digit(char, int) returns a nonnegative value) except that the first character may be an ASCII minus sign '-' ('\u002D') to indicate a negative value or an ASCII plus sign '+' ('\u002B') to indicate a positive value. The resulting short value is returned.

tags Java

Parses the string argument as a signed short in the radix specified by the second argument.


public static short parseShort(String s, int radix) throws NumberFormatException


s - a String containing the short representation to be parsed.

radix - the radix to be used while parsing s.


The short represented by the string argument in the specified radix.


NumberFormatException - If the string does not contain a parsable short.

Java Short parseShort(String s, int radix) example

  • Assign two String values.
  • Short.parseShort(firstValue);It will parses the string firstValue as signed decimal short.
  • Short.parseShort(secondValue);It will parses the string secondValue as signed decimal short.
  • Print the values after parsing.
package com.technicalkeeda;

public class App {

	public static void main(String[] args) {

		String firstValue = "225";
		String secondValue = "-20";

		short result1 = Short.parseShort(firstValue);
		short result2 = Short.parseShort(secondValue);

		System.out.println("The parse value for firstValue :- " + result1);
		System.out.println("The parse value for secondValue :- " + result2);


The short value for firstValue :- 225
The short value for secondValue :- -20

Suggested Posts



Hi there! I am founder of and programming enthusiast. My skills includes Java,J2EE, Spring Framework, Nodejs, PHP and lot more. If you have any idea that you would want me to develop? Lets connect: yashwantchavan[at][]