tags:

views:

50

answers:

1

Hi,

I have to manage XML documents and Strings in my app.

In terms of efficiency and memory usage, will a collection like ArrayList be much more expensive than String[]? Also, I could store the content as a regular String or XML. Is working with XML also more expensive? (When I say expensive, I am referring to the use of system resources.)

Those Strings will include xml's.. all i gonna do is pass them to another appz and those appz will deal with them.. nothing more..the ArrayList will hold dynamiclly around 20 Strings each.. and ill will need to 'for each' it, get the content of the string and send it to another app.

If there are differences, are they significant?

Thanks, Ray.

A: 

It depends very much on what you're doing with the strings and how you're using them.

However, from my recent experience using an ArrayList of strings for processing quickly and repeatedly, I found a String[] array 8-10 times as fast for my purposes (read string and compare in a while loop).

It seemed really odd (and annoying because I wanted dynamic size), but the execution time spoke for itself.

Like I say, this is from my own experience recently and I'm just being general. Perhaps if you provide more information on what you're trying to achieve, we may give you more specific advice.

HXCaine
ive editted the question, thanks
rayman
In that case your use is very similar to mine, and I highly recommend using String[] as I said above. My use was looping with for-each and I found the ArrayList implementation to be ridiculously slow. You said you'd have 20 strings, so it won't make that much of a difference to the app, but if you know the size in advance or will be looping multiple times, it's best to play it safe with String[], especially since that number could change.
HXCaine
Yes.. but it's much more comofortable to retrive/search/add/delete from ArrayList then String[]... thats why i was wondering about how diffrence it might take.
rayman
What I do is: use ArrayList if it's more comfortable. If the processing is likely to take more than half a second or so, use arrayList.toArray(stringArray) and process the strings instead for speed
HXCaine
i got it, thanks.
rayman