Java.lang.Byte.toString() 方法
描述
java.lang.Byte.toString() 返回一个表示此字节值的字符串对象。 该值被转换为带符号的十进制表示形式并以字符串形式返回,就像将字节值作为参数提供给 toString(byte) 方法一样。
声明
以下是 java.lang.Byte.toString() 方法的声明。
public String toString()
覆盖
类对象中的toString
参数
NA
返回值
此方法返回以 10 为底的此对象值的字符串表示形式。
异常
NA
示例
下面的例子展示了 lang.Byte.toString() 方法的使用。
package com.tutorialspoint;
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

