2

Im struggeling a little bit with arrays. My applications uses data stored in an array (res/array-xml), but I want the user to be able to create custom arraydata and store these in a file on the device. Or even better, download arraydata from the internet.

I haven't found out wether I should use XML with a custommade XMLParser or a flatfile with CSV. The use of a database is also an option, but that will most likely be added in version 2... ;-)

The arraydata is best organized in a two-dimentional array. The data looks like this;

name[0],name
name[1],name
name[2],name
address[0],streetname
address[1],streetname
address[2],streetname
city[0],name
city[1],name
city[2],name

Is there a nifty way to get this flatfile into an array looking like this:

array[0..2][0..2]name

Or, even better, a nifty way to read an XMLfile and get a array like this?

Or shuld I just start with this example and modify it to my needs?

Community
  • 1
  • 1
user1086500
  • 380
  • 5
  • 20

2 Answers2

2

Personally I wouldn't use a 2d array I would use Collections. They are easier to work with than arrays to parse XML.

http://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&ved=0CDgQFjAA&url=http%3A%2F%2Fwww.java-samples.com%2Fshowtutorial.php%3Ftutorialid%3D152&ei=OI0xT_a1E8iuiQL7v9mVAw&usg=AFQjCNHLgDmS_aRCy0OpDilqb1rqoSF1kQ

JakeWilson801
  • 1,036
  • 7
  • 20
0

You don't say whether you control the XML data from the internet. I assume that it's data you will create an distribute.

In that case, Java (and Android) has many different implementations of arrays and lists, most of which support serialization.

This Q&A should set you down the right path. Serializing and de-serializing is easy, and very useful, once you get the hang of it.

Serializing an ArrayList

Community
  • 1
  • 1
Simon
  • 14,407
  • 8
  • 46
  • 61