- Java.lang - Home
- Java.lang - Boolean
- Java.lang - Byte
- Java.lang - Character
- Java.lang - Character.Subset
- Java.lang - Character.UnicodeBlock
- Java.lang - Class
- Java.lang - ClassLoader
- Java.lang - Compiler
- Java.lang - Double
- Java.lang - Enum
- Java.lang - Float
- Java.lang - InheritableThreadLocal
- Java.lang - Integer
- Java.lang - Long
- Java.lang - Math
- Java.lang - Number
- Java.lang - Object
- Java.lang - Package
- Java.lang - Process
- Java.lang - ProcessBuilder
- Java.lang - Runtime
- Java.lang - RuntimePermission
- Java.lang - SecurityManager
- Java.lang - Short
- Java.lang - StackTraceElement
- Java.lang - StrictMath
- Java.lang - String
- Java.lang - StringBuffer
- Java.lang - StringBuilder
- Java.lang - System
- Java.lang - Thread
- Java.lang - ThreadGroup
- Java.lang - ThreadLocal
- Java.lang - Throwable
- Java.lang - Void
- Java.lang Package Useful Resources
- Java.lang - Useful Resources
- Java.lang - Discussion
Java.lang.Short.parseShort() Method
Description
The java.lang.Short.parseShort(String s, int radix) method parses the string argument as a signed short in the radix specified by the second argument.
Declaration
Following is the declaration for java.lang.Short.parseShort() method
public static short parseShort(String s, int radix) throws NumberFormatException
Parameters
s − This is a String containing the short representation to be parsed.
radix − This is the radix to be used while parsing s
Return Value
This method returns the short represented by the string argument in the specified radix.
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;
public class ShortDemo {
public static void main(String[] args) {
String str = "1000";
// 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);
// returns the string argument as a signed short in the radix
shortValue = Short.parseShort(str,2);
System.out.println("Signed decimal short value for specified String
with radix 2 is = " + shortValue);
// returns the string argument as a signed short in the radix
shortValue = Short.parseShort("11",8);
System.out.println("Signed decimal short value for specified String
with radix 8 is = " + shortValue);
}
}
Let us compile and run the above program, this will produce the following result −
Signed decimal short value for given String is = 1000 Signed decimal short value for specified String with radix 2 is = 8 Signed decimal short value for specified String with radix 8 is = 9
java_lang_short.htm
Advertisements