Sort an ArrayList of objects?

2020-05-09 14:44发布

I need some help how to sort an ArrayList of objects. I have the superclass Account and two subclasses SavingsAccount and CreditAccount. Inside the Account class I have this method to call when I want to know the account number:

// Get account number
public String getAccountNumber() {
    return accountNumber;
}

I need to sort the account numbers to get the highest number of all accounts in the objects?

The ArrayList is like this:

ArrayList<Account> accountList = new ArrayList<Account>();

Could this be done in a simple and not to comlicated way? Thanks!

标签: java
7条回答
欢心
2楼-- · 2020-05-09 15:36

You can use sort method in Collections utility and your custom implementation of Comparator interface.

查看更多
登录 后发表回答