-1

我如何从这个列表中调出一个字符串我尝试使用 get(index) 但它会发送一个错误

List<String> strlist = new ArrayList<String>();
strlist.add(datelist);
String[] strarray = strlist.toArray(new String[0]);
System.out.println(Arrays.toString(strarray));
table_4.setValueAt(strlist.get(1), 0, 0);

字符串来自 while 语句:

while (cal2.getTime().before(newDateString)) {
cal2.add(Calendar.DATE, 1);
String datelist=(format.format(cal2.getTime()));

字符串/输出将是这样的:

[May 10, 2013]

[May 11, 2013]

[May 12, 2013]

[May 13, 2013]

[May 14, 2013]

[May 15, 2013]

[May 16, 2013]

[May 17, 2013]

[May 18, 2013]  
4

1 回答 1

2

您似乎只添加了一个元素,并且 a 的第一个索引List是 0,所以您的代码应该是:

table_4.setValueAt(strlist.get(0), 0, 0);

供您参考,List有一个很好的toString()方法,所以System.out.println(strlist);如果您不需要数组做其他任何事情,您可以使用。

另一个小细节,您可以使用它strlist.toArray(new String[strlist.size()])来避免分配新数组。

编辑:

for (int y = 0 ; y < strlist2.size() ; y++)
{ 
  //This will set the strin at pos y at the y pos in the table.
  table_4.seValue(strlist2.get(y),y,0);
}
于 2013-05-30T07:15:36.827 回答