Java Short - parseShort() Method
The java.lang.Short.parseShort() method is used to parse the string argument as a signed decimal short. The characters in the string must all be decimal digits, 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, exactly as if the argument and the radix 10 were given as arguments to the parseShort(java.lang.String, int) method.
Syntax
public static short parseShort(String s) throws NumberFormatException
Parameters
s |
Specify a String containing the short representation to be parsed. |
Return Value
Returns the short value represented by the argument in decimal.
Exception
Throws NumberFormatException, if the string does not contain a parsable short.
Example:
In the example below, the java.lang.Short.parseShort() method is used to parse the string argument as a signed decimal short.
import java.lang.*; public class MyClass { public static void main(String[] args) { //creating a string holding short value String x = "25"; //creating short value short y = Short.parseShort(x); //printing the string System.out.println("The string is: " + x); //printing the short value System.out.println("The short value is: " + y); } }
The output of the above code will be:
The string is: 25 The short value is: 25
❮ Java.lang - Short