我有一个数组author-->bookName
,我想用 bookName(s) 对其进行排序。我需要在 Java 中排序bookName-->author
(通讯作者姓名)的答案
编辑:评论中的代码:
Arrays.sort(book, new Comparator<LibraryBook>() {
public int compare(LibraryBook arg0, LibraryBook arg1) {
return arg0.getBookTitle().compareTo(arg1.getBookTitle());
}
});
printBooks(book);
private static void printBooks(LibraryBook[] book){
for (int x = 0; x < book.length; ++x) {
String title = book[x].getBookTitle();
String author = book[x].getBookAuthor();
System.out.println(String.format("%30s%30s", title, author));
}
}