Best way to sort data

android, arrays, java, sorting, sql

Solution

Sort the data while taking from the database using SQL and put into array

If you are able to sort data on database level, do it. Sorting on database level is much more faster as in memory - especially if your memory is limitated in the case of many records. Also performance can be increased by an usage of indexes which provide many databases.

So if you can and are able to sort in database, sort in database. If not, sort in application but here you are limitated by memory and sorting is significantly slower.

Note: It's worth to mention that if your sorting algorithm is very changeble during runtime (with high frequency and begins changing after data are retrieved from database) it's good approach to think about sorting in application and not in database and make some analysis focused on advantages and disadvatages due to application requirements (performance for instance).

Problem

In my Android application I have to fill an arraylist object with the data taken from a database. Also the data should be sorted. So i have two ways. - Sort the data while taking from the database using SQL and put into array - Get data from database and put them into the array and sorl the data later out of these which is more efficient and less affecting the runtime. Need some help. Thank you!

Original source

Related problems