I can tell you from here that the difference between the &
operator and the &&
operator is that &&
will check the first expresion, and if it evaluates to false, then it will simply break from the check, but the &
operator will run the following expression regardless of whether or not the first one turned out to be false.
So, the code you have written will check (i<(books.size()))
, and whether or not that turns out to be false, !((books.get(i)).areYouBook(a))
will still be executed.
If however, you used &&
and (i<(books.size()))
was false, the second part of your check, which is !((books.get(i)).areYouBook(a))
, will not be executed.
I hope this helps.
Edit:
You mentioned an error being thrown when you used the &
operator instead of the &&
operator. Since the &
operator does run the second expression even if the first one is false, I'm wondering if your second expression is actually throwing an error, and is getting called when you use &
.
Edit 2:
Ok. Lets say that books
has a size of 12 (indexes 0-11) just for demonstration. So, when you use the &
operator, your while loop runs until i
is 12. When i
is 12, the loop executes (i<(books.size()))
(which returns false) and CONTINUES to execute !((books.get(i)).areYouBook(a))
. Inside the second expression, books.get(i)
is being called, when i
is 12. The books
list only goes from indexes 0-11, throwing a java.lang.IndexOutOfBoundsException
.