java - 按数组内对象内的内容对数组进行排序
问题描述
@Override
public String createExport(ArrayList<Integer> allIdList) {
ArrayList<Answer> allAnswer = new ArrayList<>();
for(int elem : vvtList) {
allAnswer.addAll(findById(elem).getAnswer());
}
for(Answer elem : allAnswer) {
allAnswer.sort(elem.getFirstSortId()); //Doesn't work
allAnswer.sort(elem.getSecondSortId()); //Doesn't work
}
return allAnswer.toString;
}
我创建了自己的类 Anwser。它包含两个整数,firstSortId 和 secondSortId。我想按它们对 allAnswer-ArrayList 进行排序。此刻的阵法列表一片混乱。
firstSortId 76 secondSortId 2
firstSortId 57 secondSortId 1
firstSortId 36 secondSortId 2
结果应该是
firstSortId 57 secondSortId 1
firstSortId 36 secondSortId 2
firstSortId 76 secondSortId 2
如何将数组按一个排序,然后按其中的两个整数排序?
解决方案
推荐阅读
- mysql - 如何在创建的字段上创建累积的 MySQL 查询?
- java - 访问 Google Sheets API 时出现 IllegalArgumentException
- python - Pandas ValueError:传递值的形状为 (6, 3),索引暗示 (6, 4)
- node.js - GoDaddy cpanel 上的 Node.JS 无法正常工作
- python - 我可以使用递归函数和列表理解来展平列表吗?
- webpack - Webpack:optimization.splitChunks.chunks 中的“all”和“initial”选项有什么区别
- javascript - 如何将鼠标指针更改为在 Javascript 中单击的图像
- apache-spark - Spark 并发性能问题 Vs Presto
- javascript - 单击addClass时的jQuery缩放
- c# - 如何使用 webapi mvc 在网络浏览器中显示 pdf