我是一名正在学习java的学生(今年才开始。我刚刚毕业,所以我也无法向我的高中老师寻求帮助),我需要一些关于如何将字符串转换为多个的帮助数组(?)。
但是,在此之后我陷入困境(因为我找不到一种方法来根据我的目的分解字符串)。
文件是这样读取的
Input: The first line will be the number of cases. For each case the first line will be Susan’s work schedule, and the second line will be Jurgen’s work schedule. The work schedules will be the date of the month (1-30) which they work. The third line will be the size of the initial TV.
有问题的文件:
3 2 5 10 2 4 10 60 2 4 10 2 5 10 60 1 2 3 4 7 8 10 12 14 16 18 20 24 26 28 30 1 2 3 6 9 10 17 19 20 21 22 23 25 27 28 29 20
我不知道该怎么做。我尝试过 .split() ,但这似乎只适用于字符串中的第一行。如果您有任何帮助/提示,我们将不胜感激!
最佳答案
您可以按行读取输入,然后对其应用正则表达式以将数字与字符串分开,例如:
String numbers = "1 2 3 4 7 8 10 12 14 16 18 20 24 26 28 30";
String[] singleNumbers = numbers.split(" ");
然后您将在 singleNumbers 数组中将这些数字用空格分隔
关于java - 将一个字符串变成多个数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16679896/