目录

String toString()

描述 (Description)

java.lang.Byte.toString()返回表示此Byte值的String对象。 该值将转换为带符号的十进制表示形式并作为字符串返回,就像将字节值作为toString(byte)方法的参数给出一样。

声明 (Declaration)

以下是java.lang.Byte.toString()方法的声明

public String toString()

覆盖 (Overrides)

Object toString

参数 (Parameters)

NA

返回值 (Return Value)

此方法返回基础10中此对象的值的字符串表示形式。

异常 (Exception)

NA

例子 (Example)

以下示例显示了lang.Byte.toString()方法的用法。

package com.iowiki;
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
↑回到顶部↑
WIKI教程 @2018