Reposting hopefully it'll be clearer
I need to sort the book titles accordingly based on the user's input and print them out accordingly. I have completed and managed to print all the books the user has entered but they are not in alphabetical order
These are my codes
import java.util.ArrayList;
import java.util.Collections;
/**
*
* @author user
*/
public class BookShelf {
ArrayList<Book> listOfBooks = new ArrayList<Book>();
public void addBook(Book book) {
listOfBooks.add(book);
}
public ArrayList<Book> returnListOfBooks() {
ArrayList<Book> myBook = new ArrayList<Book>(listOfBooks);
Collections.sort(myBook);
return myBook;
}
}
The ArrayList<Book> myBook = new ArrayList<Book>(listOfBooks);
is to return those books i have added into the array list and then I will have to sort them accordingly however, I have this error on Collections.sort(myBook);
I have no idea how to fix this. Any help is appreciated!