title: Efficiently filter an ArrayList in Java/Android
body: <p>I'm developing an Android app (Android 1.6), but this is probably a more general Java question.</p>
  
  <p>I have an ArrayList of about 10,000 objects</p>
  
  <p>the objects contain 3 strings (firstName, middleName, lastName).</p>
  
  <p>The user is presented with a "search box" on android where they can search for a particular "object" by typing in part of the name.</p>
  
  <p>I have a class (which I call Filterer) that searches through the list of 10,000 for matching objects and then returns them as a "sublist".</p>
  
  <p>The search is a little bit SLOW (especially on an Android handset) and I'm sure I'm not doing the search/filtering in the most efficient manner possible.</p>
  
  <p>Does anyone have any suggestions on how to speed up my search?  My code is below.  One possibility to to search against a secondary "masterList" that already has every piece of information in lowercase and concatenated…but there may be additional ways to improve this search that would also help.</p>
  
  <p>TIA!!</p>
  
  <pre><code>public void filterNames() {
    this.filteredList.clear();
    String sv = this.searchString.toString.trim().toLowerCase(); // search value
    for (int i = 0; i &lt; this.masterList.size(); i++) {
      MyObject d = this.masterList.get(i);
      String fn = d.getFirstName().toString().toLowerCase();
      String mn = d.getMiddleName().toString().toLowerCase();
      String ln = d.getLastName().toString().toLowerCase();
  
      if (fn.indexOf(sv) &gt;= 0 || 
          md.indexOf(sv) &gt;= 0 || 
          ln.indexOf(sv) &gt;= 0) {
        this.currentList.add(d);
      }
    }
  }
  </code></pre>