java字串轉換陣列
阿新 • • 發佈:2020-08-13
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