user1927638
user1927638

Reputation: 1173

ArrayList or SQLite

In terms of storing data in Android, would it be more efficient to use a large ArrayList or setup an SQLite database? I have ~9000 bus stops and stop names (both in String) that I need to store and I was wondering which method would be the quickest or most efficient.

Upvotes: 2

Views: 1330

Answers (3)

Vrashabh Irde
Vrashabh Irde

Reputation: 14377

1.) Store and retrieve your data from a SQLite DB since you want persistance. And since you say you have 9k+ rows a simple select will give you everything at once and you can easily filter the data as well if you need to

2.) At startup, put all your data into efficient memory structures like HashMaps(or in your case arraylists) and reference them throughout the app. This way you'll only do one time access.

3.) When in doubt build a DB. No harm, more efficient and easier to handle than files

Upvotes: 0

Nicklas Gnejs Eriksson
Nicklas Gnejs Eriksson

Reputation: 3415

If your data does not change then you could probably have it read on startup and kept in memory while the App runs. For example, having a .json file with all the stops, read it on startup, put the data in a HashMap or something that is easy to use since you will probably lookup stuff. It would probably work fine with ~9000 entries.

If you are going to add or update information about the stops during usage then the SQLite is the better choice though.

Upvotes: 0

Ahmad
Ahmad

Reputation: 72673

An ArrayList is probably a very bad idea. I assume you want the data to be persistent, so if your user kills your app your data will be lost if you use an ArrayList. A database is persistent(unless the user clears the cache of the app). So I would highly recommend using a database over an ArrayList.

Upvotes: 2

Related Questions