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);
//字符串变字符数组,小写变大写
String str = "aba";
String s = str.toUpperCase();
System.out.println(s);
char[] chars = str.toCharArray();
for (int i = 0; i < chars.length; i++) {
chars[i]-=32;
}
String s1 = new String(chars);
System.out.println(s1);
}
}
字符串,字节,字符相互转换
最新推荐文章于 2024-05-28 11:35:30 发布