title: Fastest way to search through strings stored in sqlite database
body: <p>I have large number of strings, approximately 15,000 that I stored in a SQLite database using the following code:</p>
  
  <pre><code> void addKey(String key, String value, String table) {
          SQLiteDatabase db = this.getWritableDatabase();
  
          ContentValues values = new ContentValues();
          values.put(KEY_KEY, key); // Contact Name
          values.put(KEY_VALUE, value); // Contact Phone
  
          // Inserting Row
          db.insert(table, null, values);
          db.close(); // Closing database connection
  
      }
  </code></pre>
  
  <p>And then i search through that database using the following method in order to pick out any strings that match the key im looking for:</p>
  
  <pre><code>public String searchKeyString(String key, String table){
          String rtn = "";
          Log.d("searchKeyString",table);
  
              // Select All Query
              String selectQuery = "SELECT  * FROM " + table;
  
              SQLiteDatabase db = this.getWritableDatabase();
              Cursor cursor = db.rawQuery(selectQuery, null);
  
              // looping through all rows and adding to list
              if (cursor.moveToFirst()) {
                  do {
                      Log.d("searchKeyString","searching");
  
                      if(cursor.getString(1).equals(key)) 
                          rtn = rtn + "," + cursor.getString(2);
                  } while (cursor.moveToNext());
              }
              cursor.close();
              db.close();
              Log.d("searchKeyString","finish search");
  
          return rtn;
      }
  </code></pre>
  
  <p>The goal is to do this in real time as the user is typing on the keep board so response time is key and the way it stands now it takes over a second to run through the search.</p>
  
  <p>I considered reading all of the items into an array list initially and sorting through that which might be faster, but i thought an array list of that size might cause memory issues. What is the best way to search through these entries in my database?</p>