java - 更改列表中的项目并排序然后列出
问题描述
我想访问一个对象列表并更改列表中的一些值。之后我想根据日期对列表进行排序。有可能做到这一点,我该怎么做?
这是我的代码:
public class AccountTransactions {
private int transactionID;
private int transactionCode;
private String transactionDate;
private String transactionType;
private String transactionTime;
private String transactionAmount;
private String transactionTo;
private String transactionFrom;
... // for bravety
}
Transactions.java
:
public ListtransactionsObjects getUserTransactions(SearchbyPublicKeyObject publicKeyObject){
List<AccountTransactions> transactionFrom = TransactionsRepository.findByTransactionFrom(publicKeyObject.getPublicKey());
List<AccountTransactions> transactionTo = TransactionsRepository.findByTransactionTo(publicKeyObject.getPublicKey());
//sudo code
// loop through list
// transactionTo.transactionAmount = "+" + transactionAmount
List<AccountTransactions> AllTransactions = Stream.concat(transactionFrom.stream(), transactionTo.stream())
.collect(Collectors.toList());
}
// sort AllTransactions by transactionDate which is of type 05/06/2018
解决方案
Collections.sort
用作_
// sort AllTransactions by transactionDate which is of type 05/06/2018
Collections.sort(AllTransactions, AccountTransactions::getTransactionDate);
假设您应该getTransactionDate
在AccountTransactions
其中返回您的交易date
(而不是string
您拥有的交易)。您可能需要将您的转换string
为date.
推荐阅读
- java - 不显示来自 base64_encode 的图像编码
- c# - 在listview加载xamarin表单之前如何使用活动指示器
- angular - 如果用户登录,Angular 5隐藏导航元素
- linux - Vagrant:设置同步文件夹的上下文以防止 SELinux 抱怨
- javascript - 刷新页面并从文件夹中获取最新图像
- bluetooth - MI 电动滑板车的 BLE 通信逆向工程师?
- sql-server - Reporting Services 用户作为用户权限键 - 行级权限 SSRS
- javascript - 日期选择器和时间选择器查询
- html - 如何让两条文本并排放置并响应屏幕宽度的变化?
- azure - 在 Azure Active Directory 中创建新用户时如何收到电子邮件通知