Strings that begin with a given prefix
<p>I have the following code:</p>

<pre><code>public List&lt;String&gt; function(String pre) {
    List&lt;String&gt; temp = new ArrayList&lt;&gt;();
    for(String str : list) {
        if(str.startsWith(pre)
            temp.add(str);
        if(str.charAt(0) &gt; pre.charAt(0))
            break;
    }
    return temp;
}
</code></pre>

<p>The function should return all words that begin with the given prefix.<br>
list in the code is a sorted ArrayList. This code has <code>O(n)</code> complexity.<br>
How can I improve it?<br>
e.g. to run in <code>log(n)</code> time.</p>
