title: Widget class that implements the Comparable interface that compares to method
body: <p>I'm assuming the existence of a Widget class that implements the Comparable interface and thus has a compareTo <strong>method</strong> that accepts an Object parameter and returns an int. I want to Write an efficient static method, getWidgetMatch, that has two parameters. 
  The first parameter is a reference to a Widget object. 
  The second parameter is a potentially very large array of Widget objects that has been sorted in ascending order based on the Widget <strong>compareTo</strong> method. The getWidgetMatch searches for an element in the array that matches the first parameter on the basis of the equals method and returns true if found and false otherwise. </p>
  
  <p>I will share two code I have almost working and my errors from debugging. Hopefully, someone has an answering I am not seeing.</p>
  
  <p>Code 1:</p>
  
  <pre><code>public static boolean getWidgetMatch(Widget a, Widget[] b){
      int bot=0;
      int top=b.length-1;
      int x = 0;
      int y=0;
      while (bot &gt;= top)
      {
          x = (top + bot/2);
  
          y = a.compareTo(b[x]);
  
          if (y==0) 
                  return true;
  
          if (y&lt;0) 
              top=x;
  
          else 
              bot=x;
          return false;
          }
  
      return a.equals(b[x]);
  }
  </code></pre>
  
  <p>The debug statement for this one is this, [LWidget;@5305068a
  →<br>
  false when it should be true. Am I miss a ">" sign possibly?</p>
  
  <p>Code 2:</p>
  
  <pre><code>public static boolean getWidgetMatch(Widget a, Widget[] b) {
      for(int i =0;i&lt;b.length;i++){
          if(b[i].compareTo(a)== 0)return true;
      }
      return false;
  }
  </code></pre>
  
  <p>The debug statement for this one is this, 
  [LWidget;@5305068a → true when it should be true and that is where I am most confused with this code. </p>
  
  <p>Am I miss a "+" or "-" or a "/" sign possibly?</p>
  
  <p>Thanks.</p>