public boolean add(String title, String author) { LibraryBook add; LibraryBook temp; add = new LibraryBook(title, author); bookList.add(add); if(bookList.size() > 1) System.out.println("The book with title \"" + title + "\" has been added to the library."); { for(int i = 0; bookList.size() > i; i++) { for(int j = i + 1; bookList.size() > j; j++) //checking whether the next books are followed by the book and updating it. { if(bookList.get(i).getAuthor().compareTo(bookList.get(j).getAuthor()) > 0 || (bookList.get(i).getAuthor().equals(bookList.get(j).getAuthor()) && bookList.get(i).getTitle().compareTo(bookList.get(j).getTitle()) > 0 )) { temp = bookList.get(i); bookList.set(i, bookList.get(j)); bookList.set(j, temp); } } } } return true; }