Java-lang-byte-tostring

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

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

説明

  • java.lang.Byte.toString()*は、このByteの値を表すStringオブジェクトを返します。 バイト値がtoString(byte)メソッドの引数として与えられた場合とまったく同じように、値は符号付き10進表現に変換され、文字列として返されます。

宣言

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

public String toString()

オーバーライド

クラス Object のtoString

パラメーター

NA

戻り値

このメソッドは、このオブジェクトの値の文字列表現を基数10で返します。

例外

NA

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

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 String's s1,s2
      String s1, s2;

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

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

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

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

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

String value of Byte 123 is 123
String value of Byte -123 is -123