package cn.itcast_05;
/*java
byte[] getByte():把字符串轉換成字節數組
public String(byte[] bytes):把字節數組轉換成字符串
char[] toCharArray():把字符串轉換成字符數組
static String valueOf(char[] chs):把字符數組轉換成字符串
static String valueOf(int i):把int類型的數據轉成字符串
String類的valueOf()能夠把任意類型的數據轉換成字符串
String toLowerCase():把字符串轉成小寫
String toUpperCase():把字符串轉成大寫
String concat(String str):把字符串拼接
*/
public class StringDemo {數組
public static void main(String[] args) {
// TODO Auto-generated method stub
//定義一個字符串對象
String s = "JavaSE";code
//byte[] getByte():把字符串轉換成字節數組 byte[] bys = s.getBytes(); for(int x=0; x<s.length(); x++) { System.out.println(bys[x]);//輸出的是數字:74,97,118,97,83,69 System.out.println("---------------------------------------------------"); }
//複習:
//public String(byte[] bytes):把字節數組轉換成字符串
String str = new String(bys);
System.out.println("str:" + str);//JavaSE
System.out.println("---------------------------------------------------");對象
//char[] toCharArray():把字符串轉換成字符數組 char[] chs = s.toCharArray(); for(int x=0; x<s.length(); x++) { System.out.println(chs[x]);//輸出的是字符:J,a,v,a,S,E } System.out.println("---------------------------------------------------"); //static String valueOf(char[] chs):把字符數組轉換成字符串 String ss = String.valueOf(chs);//string是靜態類型,因此能夠直接用類調用 System.out.println(ss);//JavaSE System.out.println("---------------------------------------------------"); //static String valueOf(int i):把int類型的數據轉成字符串 int i = 100; System.out.println(i);//字符串類型:100 System.out.println("---------------------------------------------------"); //String toLowerCase():把字符串轉成小寫 System.out.println(s.toLowerCase());//javase System.out.println("---------------------------------------------------"); //String toUpperCase():把字符串轉成大寫 System.out.println(s.toUpperCase());//JAVASE System.out.println("---------------------------------------------------"); //String concat(String str):把字符串拼接 String str3 = s.concat(ss); System.out.println(str3);//JavaSEJavaSE System.out.println("---------------------------------------------------"); String str4 = s + ss; System.out.println(str4);//JavaSEJavaSE System.out.println("---------------------------------------------------");
}字符串
}get