2

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.

3 Answers 3

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the response. For the database, how would I populate the database only once?
Here is a great tutorial: vogella.com/articles/AndroidSQLite/article.html, you just basically have to create the database once, insert the data and then you can query it every time you need data.
0

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.

2 Comments

Thanks for the response. What if the information stays persistent (ie non-changing stops and stop names). This information will be simply read.
Then creating a data file with all the info and packaging it with your Application, and thus reading it on startup to memory will be fine.
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.