2

I have an ArrayList of Location objects. The ArrayList typically has from 1,000 to 10,000 Location objects.

I want to be able to persist the ArrayList and then read it back in later.

I am assuming that it would be much faster to write out the entire ArrayList of Location objects as a single file rather than storing each Location object in SQLiteDB.

Can someone show me some example code to read/write an ArrayList of Location objects, or suggest a better solution?

Ted
  • 43
  • 1
  • 4

1 Answers1

0

Are you really going to have to store all of the 10k locations, delete them all and store a new set of 10k locations every time? Or just make some updates occasionally? (such as delete or add several rows). If the latter, than you want to be using SQLite as it will be monumentally easier to do those actions with the Db.

Also note that SQLite is also just a stored file on the filesystem, there isn't a DB server in the way there is with MySQL, for example.

That aside, this has been discussed before on SO, so you may want to look at these:

Android data storage - File vs SQLite

Sqlite vs File based data storing?

Community
  • 1
  • 1
Alex Florescu
  • 5,096
  • 1
  • 28
  • 49
  • Each data set is a fixed set. No inserts, deletes, no searches. It would seem to me that saving a list or an array of objects to a file as binary data and then reading back in as binary data would be much faster than using SQLite or JSON which AFAIK are based on text files. Java has ObjectOutputStream and ObjectInputStream to handle situations like this; but I understand that these rely on Serialization which I understand is very slow in Android. I was hoping that there was some efficient analog of ObjectOutputStream in Android, but apparently not? – Ted May 01 '12 at 18:12
  • you should implement Serializable.see this http://stackoverflow.com/questions/7135086/storing-a-parcelable-object-to-a-file-in-android – Zaz Gmy May 02 '12 at 08:46
  • If you're worried about speed, I think your best call is to test both for solutions for the type of data you need and benchmark the results. – Alex Florescu May 02 '12 at 08:51