Java.lang.Byte.shortValue() Method


Advertisements


Description

The java.lang.Byte.shortValue() returns the value of this Byte as a short.

Declaration

Following is the declaration for java.lang.Byte.shortValue() method

public short shortValue()

Overrides

shortValue in class Number

Parameters

NA

Return Value

This method returns he numeric value represented by this object after conversion to type short.

Exception

NA

Example

The following example shows the usage of lang.Byte.shortValue() method.

package com.tutorialspoint;

import java.lang.*;

public class ByteDemo {

   public static void main(String[] args) {

      // create 2 Byte objects b1, b2
      Byte b1, b2;

      // create 2 short primitives s1, s2
      short s1, s2;

      // assign values to b1, b2
      b1 = new Byte("10");
      b2 = new Byte("-10");

      // assign short values of b1, b2 to s1, s2
      s1 = b1.shortValue();
      s2 = b2.shortValue();

      String str1 = "short value of Byte " + b1 + " is " + s1;
      String str2 = "short value of Byte " + b2 + " is " + s2;

      // print s1, s2 values
      System.out.println( str1 );
      System.out.println( str2 );
   }
}

Let us compile and run the above program, this will produce the following result −

short value of Byte 10 is 10
short value of Byte -10 is -10

java_lang_byte.htm

Advertisements