Java2all.com  

Short





Share This Topic -

Short :

The Short class encapsulates a short value. It defines the constants MAX_VALUE and MIN_VALUE and provides the following constructors:

      Short(short s)

      Short(String str)

EX :

 import java.util.*;
public class Short_Demo
{
    public static void main(String args[])
    {
        Short s1 = new Short((short)2345);
        for(int i = 32765; i<=32775; i++)
        {
            Short s2 = new Short((short)i);
            System.out.println("s2 = " + s2);
        }
        System.out.println("s1 Object = " + s1);
        System.out.println("Minimum Value of Short = " + Short.MIN_VALUE);
        System.out.println("Maximum Value of Short = " + Short.MAX_VALUE);
        System.out.println("s1* 2 = " + s1.shortValue()*2);
        Short s3 = new Short("2345");
        System.out.println("s3 Object = " + s3);
        System.out.println("(s1==s3)? " + s1.equals(s3));
        Short s4 = Short.valueOf("10", 16);
        System.out.println("s4 Object = " + s4);
    }
}

 
Output :
 
s2 = 32765
s2 = 32766
s2 = 32767
s2 = -32768
s2 = -32767
s2 = -32766
s2 = -32765
s2 = -32764
s2 = -32763
s2 = -32762
s2 = -32761
s1 Object = 2345
Minimum Value of Short = -32768
Maximum Value of Short = 32767
s1* 2 = 4690
s3 Object = 2345
(s1==s3)? true
s4 Object = 16