Java Short - valueOf() Method
The java.lang.Short.valueOf() method returns a Short object holding the value given by the specified String. The argument is interpreted as representing a signed decimal short, exactly as if the argument were given to the parseShort(java.lang.String) method. The result is a Short object that represents the short value specified by the string.
In other words, this method returns a Short object equal to the value of: new Short(Short.parseShort(s)).
Syntax
public static Short valueOf(String s) throws NumberFormatException
Parameters
s |
Specify the string to be parsed. |
Return Value
Returns a Short object holding the value represented by the string argument.
Exception
Throws NumberFormatException, if the String does not contain a parsable short.
Example:
In the example below, the java.lang.Short.valueOf() method returns a Short object holding the value given by the specified String.
import java.lang.*; public class MyClass { public static void main(String[] args) { //creating a string holding short value String x = "25"; //creating Short object Short y = Short.valueOf(x); //printing the string System.out.println("The string is: " + x); //printing the Short object System.out.println("The Short object is: " + y); } }
The output of the above code will be:
The string is: 25 The Short object is: 25
❮ Java.lang - Short