Peter
Peter

Reputation: 5131

Searching through large list of ordered strings

Right now as part of my android app I have a .csv file that contains aobut 15,000 lines stored on the sd card of the phone. Every time my app launches it reads in those 15,000 lines into two parallel arrays. I do this for 3 files so in total I have 6 arrays storing 15,000 elements each. I need to search through these items quickly while maintaining order.

I'm worried if I keep the code the way it is I'm going to start running out of memory on phones and having the app crash. Would it be faster just to search through the csv file using readline instead of reading the entirety of each array into array lists so I don't run into memory issues? Is there a better way to do this while maintaining order?

The content on the SD card is in the following form:

New York, test1
New Jersey, test2
Colorado, test3
Arkansas, test4
New York, test5
etc..

Upvotes: 1

Views: 171

Answers (2)

Kumar Vivek Mitra
Kumar Vivek Mitra

Reputation: 33544

- If you want to search using the arrays, then its best to convert the array to List using Arrays.asList() method and then use the contains() method to search for the data.

- The other way to do this, will be using the SQLite DataBase

Upvotes: 1

antew
antew

Reputation: 7478

I think a better solution would be to store them in an SQLite database and use ORDER BY when querying, and only query what data you need at that moment.

Upvotes: 5

Related Questions