title: Java equivalent of c++ equal_range (or lower_bound & upper_bound)
body: <p>I have a List of object sorted and I want to find the first occurrence and the last occurrence of an object. In C++, I can easily use std::equal_range (or just one lower_bound and one upper_bound). </p>
  
  <p>For example:</p>
  
  <pre><code>bool mygreater (int i,int j) { return (i&gt;j); }
  
  int main () {
    int myints[] = {10,20,30,30,20,10,10,20};
    std::vector&lt;int&gt; v(myints,myints+8);                         // 10 20 30 30 20 10 10 20
    std::pair&lt;std::vector&lt;int&gt;::iterator,std::vector&lt;int&gt;::iterator&gt; bounds;
  
    // using default comparison:
    std::sort (v.begin(), v.end());                              // 10 10 10 20 20 20 30 30
    bounds=std::equal_range (v.begin(), v.end(), 20);            //          ^        ^
  
    // using "mygreater" as comp:
    std::sort (v.begin(), v.end(), mygreater);                   // 30 30 20 20 20 10 10 10
    bounds=std::equal_range (v.begin(), v.end(), 20, mygreater); //       ^        ^
  
    std::cout &lt;&lt; "bounds at positions " &lt;&lt; (bounds.first - v.begin());
    std::cout &lt;&lt; " and " &lt;&lt; (bounds.second - v.begin()) &lt;&lt; '\n';
  
    return 0;
  }
  </code></pre>
  
  <p>In Java, there seems to be no simple equivalence? How should I do with the equal range with </p>
  
  <pre><code>List&lt;MyClass&gt; myList;
  </code></pre>
  
  <p>By the way, I am using a standard import java.util.List; </p>