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();
}