/*
byte[] getBytes():将字符串转换为字节数组
char[] toCharArray():将字符串转换为字符数组
static String copyValueOf(char[] chs):将字符数组转换为字符串
static String valueOf(char[] chs):将字节数组转换为字符串
static String valueOf(int i):将int型数转换为字符串
String toLowerCase():将字符串全部转换成小写
String toUpperCase():将字符串全部转换成大写
String concat(String str): 拼接字符串
*/
public class StringDemo {
public static void main(String[] args) {
//byte[] getBytes()
String s = "abcdefg";
byte[] byts = s.getBytes();
for (int i = 0; i < byts.length; i++) {
System.out.println(byts[i]);
}
//char[] toCharArray()
char[] cha = s.toCharArray();
for (int i = 0; i < cha.length; i++) {
System.out.println(cha[i]);
}
//static String copyValueOf(char[] chs)
String s2 = String.copyValueOf(cha);
System.out.println(s2);
//static String valueOf(char[] chs)
String s3 = String.valueOf(cha);
System.out.println(s3);
//static String valueOf(int i)
int a = 95;
String s4 = String.valueOf(a);
System.out.println(s4);
// String toLowerCase():
System.out.println(s3.toLowerCase());
// String toUpperCase():
System.out.println(s3.toUpperCase());
// String concat(String str):
System.out.println(s.concat(s));
}
}
|
|