【发布时间】:2014-09-06 10:00:32
【问题描述】:
我在ArrayList<String> 中有这样的输入:
cat eats mouse
mouse eats cheese
cheese is tasty
(应该忽略空白行,因为我将从文件中读取此输入)
我想将它转换成二维字符串数组,其尺寸为[no. of elements in ArrayList][3]。
没有。 3 是固定的,即每个句子将有 3 个单词。 像这样:
"cat" "eats" "mouse"
"mouse" "eats" "cheese"
"cheese" "is" "tasty"
这是我尝试过的:
public static int processData(ArrayList<String> array)
{
String str[]=new String[array.size()];
array.toArray(str);
String str1[][]=new String[str.length][5];
for(int i=0;i<str.length;i++)
{
str1[i][]=str.split("\\s+"); //i want to do something like this, but this is showing errors.
}
return 0; //this is temporary, I will be modifying it
}
如果我不清楚,请告诉我。
【问题讨论】: