Java.lang.Short.parseShort() Method

Advertisements


Description

The java.lang.Short.parseShort(String s) method parses the string argument as a signed decimal short.

Declaration

Following is the declaration for java.lang.Short.parseShort() method

public static short parseShort(String s) throws NumberFormatException

Parameters

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

Return Value

This method returns the short value represented by the argument in decimal.

Exception

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

Example

The following example shows the usage of java.lang.Short.parseShort() method.

package com.tutorialspoint;

import java.lang.*;

public class ShortDemo {

   public static void main(String[] args) {

     String str = "250";

     // returns signed decimal short value of string
     short shortValue = Short.parseShort(str); 
    
     // prints signed decimalshort value
     System.out.println("Signed decimal short value for given String is =
     " + shortValue);  
  }
}   

Let us compile and run the above program, this will produce the following result:

Signed decimal short value for String is = 250



Advertisements
Advertisements