title: Which is more efficient, Sorting and then Binary Search over a Collection or Linear Search in java
body: <p>Suppose I am having a Collection of object:</p>
  
  <pre><code>List&lt;String&gt; myList = populateMyArrayList();
  //Here I am having an ArrayList with 1000 elements
  </code></pre>
  
  <p>Which is the better approach:</p>
  
  <p><strong>1 : Mergesort then Binary Search</strong></p>
  
  <pre><code>Collections.sort(myList);
  int keyIndex = Collections.binarySearch(myList, key);
  </code></pre>
  
  <p><strong>2 : Sequential Search</strong></p>
  
  <pre><code>for(String s : myList){
     if(s.equals(key)){
        return s;
     }
  }
  </code></pre>
  
  <p>Should there be a difference in searching approach based on the size of the collection to be searched? If YES then how to decide.</p>
  
  <p><strong>EDIT1:</strong> Suppose I have to search the list a couple of times, and no new elements will be added in the list. </p>
  
  <p><strong>EDIT2:</strong> I could have gone for a <code>HashSet</code>, but I am actually having a <code>List&lt;CustomObject&gt;</code> and I can search the <code>List</code> multiple times based on different attributes of CustomObject. So I can't have a overridden <code>equals</code> method in my CustomObject</p>