1. 程式人生 > 實用技巧 >java字串轉換陣列

java字串轉換陣列

public class Test {
public static void main(String args[]) {
String str = "helloworld";
char[] data = str.toCharArray();// 將字串轉為陣列
for (int x = 0; x < data.length; x++) {
System.out.print(data[x] + "  ");
data[x] -= 32;  //ASCLL減少32位變成大寫
System.out.print(data[x] + "  ");
}
System.out.println(new String(data));
}
}

輸出:h H e E l L l L o O w W o O r R l L d D HELLOWORLD