Java程序将字节转换为字符串
在Java中,有多种方法可以将字节转换为字符串。
使用toString()方法,您可以轻松地将字节转换为字符串,如下所示-
示例
public class Demo {
public static void main(String[] args) {
byte res = 87;
//字节到字符串
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
热门推荐
10 祝孙辈生日祝福语简短
11 恋人跨年祝福语大全简短
12 考大学敬酒简短祝福语
13 开工投产大吉祝福语 简短
14 偶然结婚祝福语朋友简短
15 感谢学长学姐祝福语简短
16 戏精的祝福语简短
17 我要结婚祝福语简短
18 婚前女儿生日祝福语简短