title: Find Range in which value lies in Java
body: <p>Suppose, I have an unsorted array of ranges.
  For e.g </p>
  
  <pre><code>class CreditRange{
     long credits;
     int id;
  }
  </code></pre>
  
  <p>Now I want to find, given credit count value belongs to which one of the CreditRange.</p>
  
  <p>Possible <code>Set&lt;CreditRange&gt;</code> of values can be </p>
  
  <pre><code>CreditRange :{id:1,credits:0}
  CreditRange :{id:2,credits:100}
  CreditRange :{id:3,credits:500}
  CreditRange :{id:4,credits:250}
  </code></pre>
  
  <blockquote>
    <p>Case 1 : Now when user enters Credits = 50, this range comparator should give
    answer as</p>
  </blockquote>
  
  <p><code>CreditRange :{id:1,credits:0}</code></p>
  
  <blockquote>
    <p>Case 2 : Now when user enters Credits = 300, this range comparator should give
    answer as</p>
  </blockquote>
  
  <p><code>CreditRange :{id:4,credits:250}</code></p>
  
  <blockquote>
    <p>Case 3 : Now when user enters Credits = 600, this range comparator should give
    answer as</p>
  </blockquote>
  
  <p><code>CreditRange :{id:3,credits:500}</code></p>
  
  <p>We can assume the ranges array takes ~1M and fits the memory. I am looking for an easy algorithm, which uses only standard JDK collections without any 3d-party libraries and special data structures, but works reasonably fast.</p>
  
  <p>What would you suggest?</p>