我正在使用 XML 解析器,结果我的ArrayList
对象得到了一个:
ArrayList <Datapoint> itemsList = parseXML();
一个 Datapoint 对象由以下字符串组成:
name: a
stateBased: b
mainNumber: c
dptID: d
groupadress: e
priority: f
我已经能够使用以下代码显示所有对象:
for(int i=0;i<itemsList.size();i++)
{
item = itemsList.get(i);
parsedData = parsedData + "----->\n";
String name = parsedData + "Name: " + item.getName() + "\n";
String stateBased = parsedData + "stateBased: " + item.getStateBased() + "\n";
String mainNumber = parsedData + "mainNumber: " + item.getMainNumber() + "\n";
String dptID = parsedData + "dptID: "+ item.getDptID() + "\n";
String groupadress = parsedData + "Groupadress: "+ item.getGroupadress() + "\n";
String priority = parsedData + "priority: "+ item.getPriority() + "\n";
}
例如,将 5 个字符串数组作为我的 ArrayList 中的一个对象,包括上面显示的字符串,那就太好了。
String [] Object 1 = {name = a, stateBased = b, dptID =c, ..}
String [] Object 2 = {name = d, stateBased = e, dptID =f, ..}
String [] Object 3 = {name = g, stateBased = h, dptID =i, ..}
但是我如何以编程方式在每次迭代中创建一个 StringArray 呢?像这样的东西:
for(int i=0;i<itemsList.size();i++)
{
item = itemsList.get(i);
String [] [i] = new String [itemsList.size()];
//insert strings to the array
}
我怎样才能意识到这一点或有什么替代方案?
谢谢!