Java-lang-byte-tostring-byte

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

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

説明

  • java.lang.Byte.toString(byte b)*は、指定されたバイトを表す新しいStringオブジェクトを返します。 基数は10と想定されます。

宣言

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

public static String toString(byte b)

パラメーター

*b* -変換されるバイト

戻り値

このメソッドは、指定されたバイトの文字列表現を返します。

例外

NA

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

package com.finddevguides;

import java.lang.*;

public class ByteDemo {

   public static void main(String[] args) {

     //create a byte primitive bt and asign value
      byte bt = 20;

     //create a String s
      String s;

     /**
 *static method is called using class name. Assign
      * string representation of bt to s
       */
      s = Byte.toString(bt);

      String str = "String representation of byte primitive " +bt+ " is " +s;

     //print s value
      System.out.println( str );
   }
}

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

String representation of byte primitive 20 is 20