Java-lang-byte-shortvalue

提供:Dev Guides
移動先:案内検索

Java.lang.Byte.shortValue()メソッド

説明

  • java.lang.Byte.shortValue()*は、このByteの値をshortとして返します。

宣言

以下は* java.lang.Byte.shortValue()*メソッドの宣言です

public short shortValue()

オーバーライド

クラス Number のshortValue

パラメーター

NA

戻り値

このメソッドは、short型への変換後、このオブジェクトが表す数値を返します。

例外

NA

次の例は、lang.Byte.shortValue()メソッドの使用法を示しています。

package com.finddevguides;

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 );
   }
}

上記のプログラムをコンパイルして実行すると、次の結果が生成されます-

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