Java Short valueOf Example

Short class valueOf method example. This example shows you how to use valueOf method.


Short class valueOf method example. This example shows you how to use valueOf method. This is static method and returns Short Instance for specified short value.


Here is the code.
/**
 * @(#) ValueOfShort.java
 * A class representing use of method valueOf() of Short class in java.lang Package.
 * @Version  02-May-2008
 @author   Rose India Team
 */
class ValueOfShort{
  public static void main(String[] args){
    short shortNum = 123;
    String str = "1001";

    //Method returns a Short instance representing given short value.This is static method.
      Short ShortValue = Short.valueOf(shortNum);
    System.out.println("Short object instance value for specified short is : " + ShortValue);

    //Method returns a Short object holding the value given by the specified String.This is static method.
    ShortValue = Short.valueOf(str);
    System.out.println("Short object instance value for specified String is : " + ShortValue);

    //Method returns a Short object holding the value from the specified String according to radix.
    //This is static method
    ShortValue = Short.valueOf(str , /*Radix*/;
    System.out.println("Short object instance value for specified String with radix 2 is : " + ShortValue);

         ShortValue = Short.valueOf("11" /*Radix*/;
         System.out.println("Short object instance value for specified String with radix 8 is : " + ShortValue);
  }  
}

Post Comment
Name:
E-mail:
Contact no :
Comments:
  Refresh Image
Verify Image:
 
 
Your Comment's
 
 
 

HOME | COPYRIGHT | CONTACT US