String的转换功能
byte [ ] getBytes( ); 把字符串转化为字节数组
char [ ] toCharArray( ) ;把字符串转化为字符数组
static String valueOf( char [ ] chs ): 把字符数组转化为字符串
static String valueOf( int i ): 把int类型的数据转化为字符串
String类的valueOf( )方法可以把任意类型的数据转成字符串
String toLowerCase( ): 把字符串转成小写
String toUpperCase( ); 把字符串转换成大写
String concat( String str); 把字符串拼接
public static void main(String[] args) {
String s = "helloWorld";
byte[] b = s.getBytes();
for (int i = 0; i < b.length; i++) {
System.out.print(b[i] + " ");
}
System.out.println();
char[] c = s.toCharArray();
for (int x = 0; x < c.length; x++) {
System.out.print(c[x] + " ");
}
System.out.println();
char[] c2 = { 'h', 'e', 'l', 'l', 'o' };
String s2 = String.valueOf(c2);
System.out.println(s2);
int x=123456;
String s3=String.valueOf(x);
System.out.println(s3);
char[] c1=s3.toCharArray();
for (int i = 0; i < s3.length(); i++) {
System.out.print(c1[i] + " ");
}
String s4=s.toUpperCase();
System.out.println(s4);
String s5=s4.concat(s2);
System.out.println(s5);
}