-1

我正在使用 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
}

我怎样才能意识到这一点或有什么替代方案?

谢谢!

4

1 回答 1

0

我可以使用以下代码解决问题:

ArrayList <Datapoint> itemsList = parseXML();
String[itemsList.size()][4] = new String();

for(int i=0;i<itemsList.size();i++)
{
     item = itemsList.get(i);      
     String [i] [0] = item.getName();
     String [i] [1] = item.getStateBased();
     String [i] [2] = item.getMainNumber();
     String [i] [3] = item.getGroupadress();
     String [i] [4] = item.getPriority();
}

并且private static String[][] String = null;被定义为全局变量。

于 2012-09-18T09:03:38.300 回答