Your default constructor Library() initializes the allBook member variable twice, with the same value in each case. Probably not what you had in mind. The immediate fix is to remove the (re) assignment in the default constructor.
Now you have two different constructors that do the right thing two different ways. To save yourself maintenance headaches, you'd normally prefer to have one code path that does "everything", so it would be good to combine the two. There are two different ways of doing that, depending on the requirements....
Consider this test.
ArrayList source = new ArrayList();source.add(book1);source.add(book2);source.add(book3);Library library = new Library(source);library.add(book4);
At this point, the library should contain four books. But how many books should the source array contain?
If the answer is four, the the library is supposed to be modifying the array it was passed. In that case, the easy answer to the constructor problem is to have the default constructor call the other, like so:
Library () { this(new ArrayList<Book>);}
On the other hand, if the source array should still contain three books, then the Library should contain a copy of the ArrayList, rather than holding onto the original. If that's your requirement, then the good answer is to go the other way around - initialize the allBook member where you declare it, but use copy semantics when you are passed the ArrayList
ArrayList<Book> allBook = new ArrayList<Book> ();Library () {}Library (ArrayList<Book> books) { allBook.addAll(books);}
Your code in this version of the puzzle is very confused about Books, titles, and Strings. Your requirements said
public ArrayList findTitles(String title)
but the signature in your class is
public ArrayList<Book> findTitles(Book title)
The code in a number of places suggests that, once upon a time, you thought all books were just Strings, and then you changed your mind. Your compiler should be telling you that you aren't being consistent.
The requirements for findTitles says that you should be returning an ArrayList of books with matching titles. That means you probably need to be creating a new ArrayList, and then add()ing the matching Books to it. The code you've written returns all of the books, but takes extra time to compare at the books first. You probably don't want to call Book.compareTo (although you can implement the solution correctly that way), but instead Book.getTitle().equals(otherBook.getTitle())
There are better answers than for loops for visiting all of the elements in an ArrayList. See Iterable. Since you've written Book.toString() already, you can start Library.toString() by building a big String out of all of the Book.toString()s.