Java.lang.Byte 类

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

语法

public String toString()

参数

不需要参数。

返回值

返回以 10 为基数表示该对象值的字符串。

异常

无。

示例:

在下面的示例中,java.lang. Byte.toString() 方法返回一个表示给定 Byte 值的 String 对象。

import java.lang.*;

public class MyClass {
  public static void main(String[] args) {
    
    //创建Byte对象
    Byte x = 25;

    //打印Byte对象
    System.out.println("The Byte object is: " + x); 

    //创建并打印字符串表示形式
    //Byte 对象的值
    String x_tostring = x.toString();
    System.out.println("The string value of Byte is: " + x_tostring);   
  }
}

上述代码的输出将是:

The Byte object is: 25
The string value of Byte is: 25