Java 程序将字节转换为字符串
在 Java 中,转换字节到字符串的方法是多种多样的。
使用 toString() 方法,您可以轻松地将字节转换为字符串,如下所示 −
示例
public class Demo {
public static void main(String[] args) {
byte res = 87;
// byte to string
System.out.println(Byte.toString(res));
}
}输出
87
在上面的示例中,我们获取了一个字节值。
byte res = 87;
然后,使用 toString() 方法将此值转换为字符串,如下所示 −
Byte.toString(res);
我们再看一个将字节转换为字符串的示例。
示例
public class Demo {
public static void main(String[] args) {
byte val = 77;
System.out.println(new String(new byte[] {val}));
}
}输出
M
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP