Java中字符串轉數組的方法有多種,以下是其中三種常見的方法:
String str = "Hello World";
char[] charArray = str.toCharArray();
String str = "Hello,World";
String[] strArray = str.split(",");
String str = "Hello,World";
StringTokenizer tokenizer = new StringTokenizer(str, ",");
String[] strArray = new String[tokenizer.countTokens()];
int i = 0;
while (tokenizer.hasMoreTokens()) {
strArray[i++] = tokenizer.nextToken();
}