Java.lang.Short.valueOf() Method


Advertisements


Description

The java.lang.Short.valueOf(String s) method returns a Short object holding the value given by the specified String.

Declaration

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

public static Short valueOf(String s) throws NumberFormatException

Parameters

  • s -- This is the string to be parsed.

Return Value

This method returns a Short object holding the value represented by the string argument.

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 = "600";
    
   // 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);
  }
}

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 = 600

java_lang_short.htm

Advertisements