I am parsing an XML file through Android Pull Parser technique. First, have a look at the below XML file:
<childs>
    <students>
        <name> hello </name>
        <address> xyz </address>
    </stdents>      
    <students>
        <name> abc </name>
        <address> def </address>
    </stdents>      
</childs>
Consider that I'm parsing the above file. Now, my problem is that I want to create a separate array for name and address. So while parsing, I want to store 1st student's data in name[0] and address[0] and the next student's data in name[1] and address[1]. In short, array size is extending as more data is parsed.
Is there any way to do so? I mean to create a dynamic extendable array? Or if there is another way to do so then please help me to fight with this problem.
You could use Vector<String> and then (if you need an array) copy the data to array(s) using toArray method.
    Vector<String> v = new Vector<String>();
    for (int i=0; i<10; i++)
        v.add(new String(Integer.toString(i)));
    Object s[] = v.toArray();
    for(int i=0; i<10; i++)
        str = s[i].toString();
Another option:
    String a[] = {};
    v.toArray(a);
                        You use and List array like this
List<String> name=new ArrayList<String>();
List<String> address=new ArrayList<String>(); 
name.add(StudyParser.getValue(eimg, "name"));  
address.add(StudyParser.getValue(eimg,"address")
where StudyParser.getValue(); is method which u call to get data
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With