Search code examples
androidperformancesearchbar

Search city name from large list stored in file


I want to implement a search bar where I have a big file which contains all cities names, data stored in the file in below format.

["Mumbai","Delhi","Bengaluru",...upto 1500]

What is the best way to implement search bar for these type of data?

should I load all cities names in a list? should I store all cities names in local DB?


Solution

  • It depends on your requirement whether you want to make search online or offline.If it goes offline search, you have to store those records in local DB otherwise implement online search would be efficient.

    Or you can use both ways by fetching the 1500 records first time as a separate process and save it in local.

    For search bar you can use List as basics but there are some other optionals. Generally, you should use the right tool for the job. If you don't want duplicates, use Set (or SortedSet if you want ordering, or LinkedHashSet)

    Check this when to use Set vs. Collection?