I'm trying to find a book in an arraylist of books by using the book's name.
When I try to add a book that's not in the book arraylist, it gives me the arrayoutofbounds exception index:3, size:3.... how can I fix that ?
public Book findBookByName(String bookNameToFind)
{
boolean found = false;
String bookName;
int index = 0;
while(!found)
{
bookName = bookLibrary.get(index).getTitle();
if(bookName.equals(bookNameToFind))
{
found = true;
}
else
{
index++;
}
}
return bookLibrary.get(index);
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…