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();
}
辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读: java虚拟空间租用要注意什么