public class TestClass {
public static void main(String[] args) {
String a = "cccc";
//字符串转字节
byte[] bytes = a.getBytes();
for (byte aByte : bytes) {
System.out.println(aByte);
}
//字符串转char
char[] chars = a.toCharArray();
for (char aChar : chars) {
System.out.println(aChar);
}
//字节转字符串
byte[] bytes1 = {99, 99, 99, 99};
String s = new String(bytes1);
System.out.println(s);
//字符转字符串
char[]chars1={'c','c','c','c'};
String s1 = new String(chars1);
System.out.println(s1);
}
}
来源:CSDN
作者:小白爱Python
链接:https://blog.csdn.net/weixin_45010894/article/details/103569166