Java Data Type Tutorial - Java Number.shortValue()








Syntax

Number.shortValue() has the following syntax.

public short shortValue()

Example

In the following code shows how to use Number.shortValue() method.

//  ww w.j  a v a 2s. c  o  m
public class Main {

   public static void main(String[] args) {

      // get a number as float
      Number x = new Float(123456f);

      // get a number as double
      Number y = new Double(9876);

      // print their value as short
      System.out.println("x as float :" + x
              + ", x as short:" + x.shortValue());
      System.out.println("y as double:" + y
              + ", y as short:" + y.shortValue());

   }
}

The code above generates the following result.