
- Java.lang Package classes
- 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 extras
- Java.lang - Interfaces
- Java.lang - Errors
- Java.lang - Exceptions
- Java.lang Package Useful Resources
- Java.lang - Useful Resources
- Java.lang - Discussion
Java.lang.Short.valueOf() Method
Description
The java.lang.Short.valueOf(String s, int radix) method returns a Short object holding the value extracted from the specified String when parsed with the radix given by the second argument.
Declaration
Following is the declaration for java.lang.Short.valueOf() method
public static Short valueOf(String s, int radix) throws NumberFormatException
Parameters
s − This is the string to be parsed.
radix − This is the radix to be used in interpreting s
Return Value
This method returns a Short object holding the value 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.valueOf() method.
package com.tutorialspoint; import java.lang.*; public class ShortDemo { public static void main(String[] args) { short shortNum = 100; String str = "1000"; // returns Short object representing given short value Short ShortValue = Short.valueOf(shortNum); // displays the short object value System.out.println("Short object representing the specified short value = " + ShortValue); // returns a Short object holding the value given by the specified String ShortValue = Short.valueOf(str); // displays the short object value System.out.println("Short object holding the value given by the specified String = " + ShortValue); /* returns a Short object holding the value from the specified String according to radix. */ ShortValue = Short.valueOf(str , 2) ; // displays the short object value System.out.println("Short object value for specified String with radix 2 =" + ShortValue); // returns a Short object holding the value for string to radix ShortValue = Short.valueOf("15" , 8) ; // displays the short object value System.out.println("Short object value String 15 with radix 8 = " + ShortValue); } }
Let us compile and run the above program, this will produce the following result −
Short object representing the specified short value = 100 Short object holding the value given by the specified String = 1000 Short object value for specified String with radix 2 = 8 Short object value String 15 with radix 8 = 13
java_lang_short.htm
Advertisements