多种方法:
1.Book类继承comparable接口
2.自定义比较器
3.for循环
Book类继承comparable接口
import java.util.Comparator; public class Book implements Comparable<Book> { private String name ; private int price ; public String getName() { return name; } public void setName(String name) { this.name = name; } public int getPrice() { return price; } public void setPrice(int price) { this.price = price; } public Book(String name, int price) { this.name = name; this.price = price; } public Book() { } @Override public String toString() { return "Book{" + "name='" + name + '\'' + ", price=" + price + '}'; } @Override public int compareTo(Book o) {