Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6657145
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:43:53+00:00 2026-05-26T01:43:53+00:00

Due to simplicity i have a text file with entries separated by ; and

  • 0

Due to simplicity i have a text file with entries separated by ; and parses every line into an object. The problem is that the text file contains almost 10 000 rows.

I also need to create keys for each object im parsing so i can filter the results in a search interface.

It takes almost 16 seconds in emulator to parse the text and add the keys. I’m i doing something wrong here? Or is there a more efficient way?

Here is my database singleton:

    public class Database {

        private static Database instance = null;    private final Map<String, List<Stop>> mDict = new ConcurrentHashMap<String, List<Stop>>();

        public static Database getInstance() {      if (instance == null) {             instance = new Database();      }       return instance;    }       public List<Stop> getMatches(String query) {
            List<Stop> list = mDict.get(query);
            return list == null ? Collections.EMPTY_LIST : list;
        }
             private boolean mLoaded = false;

            /**
             * Loads the words and definitions if they haven't been loaded already.
             *
             * @param resources Used to load the file containing the words and definitions.
             */
            public synchronized void ensureLoaded(final Resources resources) {
                if (mLoaded) return;

                new Thread(new Runnable() {
                    public void run() {
                        try {
                            loadStops(resources);
                        } catch (IOException e) { 
                            throw new RuntimeException(e);
                        }
                    }
                }).start();
            }

            private synchronized void loadStops(Resources resources) throws IOException
            {
                if (mLoaded) return;

                Log.d("database", "loading stops");

                InputStream inputStream = resources.openRawResource(R.raw.allstops);
                BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));

                try {
                    String line;
                    while((line = reader.readLine()) != null) {
                        String[] strings = TextUtils.split(line, ";");
                        addStop(strings[0], strings[1], strings[2]);
                    }
                } finally {
                    reader.close();
                }

                Log.d("database", "loading stops completed");

                mLoaded = true;
            }

            private void addStop(String name, String district, String id) {
                Stop stop = new Stop(id, name, district);

                int len = name.length();
                for (int i = 0; i < len; i++) {
                    String prefix = name.substring(0, len - i).toLowerCase();
                    addMatch(prefix, stop);
                }
            }

            private void addMatch(String query, Stop stop) {
                List<Stop> matches = mDict.get(query);
                if (matches == null) {
                    matches = new ArrayList<Stop>();
                    mDict.put(query, matches);
                }
                matches.add(stop);
            }

    }

Here is some sample data:

Mosseporten Senter;Norge;9021014089003000;59.445422;10.701055;273
Oslo Bussterminal;Norge;9021014089004000;59.911369;10.759665;273
Långegärde;Strömstad;9021014026420000;58.891462;11.007767;68
Västra bryggan;Strömstad;9021014026421000;58.893080;11.009997;7
Vettnet;Strömstad;9021014026422000;58.903184;11.020739;7
Ekenäs;Strömstad;9021014026410000;58.893610;11.048821;7
Kilesand;Strömstad;9021014026411000;58.878472;11.052983;7
Ramsö;Strömstad;9021014026430000;58.831531;11.067402;7
Sarpsborg;Norge;9021014089002000;59.280937;11.111763;273
Styrsö;Strömstad;9021014026180000;58.908110;11.115818;7
Capri/Källviken;Strömstad;9021014026440000;58.965200;11.124384;63
Lindholmens vändplan;Strömstad;9021014026156000;58.890212;11.128393;64
Öddö;Strömstad;9021014026190000;58.923490;11.130767;7
Källviksdalen;Strömstad;9021014026439000;58.962414;11.131962;64
Husevägen;Strömstad;9021014026505000;58.960094;11.133535;274
Caprivägen;Strömstad;9021014026284000;58.958404;11.134281;64
Stensviks korsväg;Strömstad;9021014026341000;59.001499;11.137203;63
Kungbäck;Strömstad;9021014026340000;59.006056;11.140313;63
Kase;Strömstad;9021014026173000;58.957649;11.141904;274
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T01:43:54+00:00Added an answer on May 26, 2026 at 1:43 am

    You should add the information into a SQLite database and ship the app with the database in res/raw.

    Additionally, the db file can often be effectively compressed into a zip file.

    See this for more information: Ship an application with a database

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Due to a number of constraints that I won't get into, I have to
The problem: I have a legacy php app that is coded in no particular
Due to 0 responses, I'm guessing that my LEFT JOIN question got into too
Due to weird domain/subdomain cookie issues that I'm getting, I'd like to know how
Due to our clients authentication and network topology we have a number of Windows
Due to network or some other reasons, some sites do not have their css
Due to the flooding examples of implementing logger using Singleton pattern, I have just
I have a simple page view tracker that uses a combination of PHP and
Recently, I've started experimenting with Mercurial, due to the fact that it always attracted
Due to an architecture I must work with that likely breaks a lot of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.