Im working on a project in which it reads book titles in from a .txt file and puts them into an arraylist, then the arraylist is converted to an array, The user enters a number which is the books reference number, then it does a linear search and a binary search to find that book. Im just having a trouble with the code for the binary search,as i have almost no idea how to do it, heres what I have:

```
   private void FindItActionPerformed(java.awt.event.ActionEvent evt) {                                       
String input;

input = Input.getText();

for(int i=0; i<bookList.length; i++){
if (bookList[i].referenceNumber.equals(input)){
    Output1.setText("The Book is " + bookList[i].title);
}
}

```

Above is the code for the linear search, which works fine. Below is what i think i need for the binary search but again, i am not sure and cannot figure it out. 

```
int right = 0, left = bookList.length;
while(right<= left){
    int middle = (right + left)/2;
    if( bookList[middle].referenceNumber.equals(input)){
        Output2.setText("The book is " + bookList[middle].title);     
    }
}

}    

```

Here is the class and the arrays

```
 public class Book{
String referenceNumber, title;

public Book(String _referenceNumber, String _title){
   referenceNumber = _referenceNumber;
   title = _title;
}
}

 ArrayList <Book> Books = new ArrayList <Book> ();
 Book [] bookList;

```

Thanks for any help you may be able to offer, This is a bit tricky for me.