当前位置:网站首页>如何让一个list根据另一个list的顺序排序
如何让一个list根据另一个list的顺序排序
2022-06-23 17:43:00 【热爱生活的猴子】
直接上代码:
//首先要保证List<User> users和List<Long> userIds
public void setListOrder(List<User> users, List<Long> userIds){
users.sort((o1,o2) -> {
int io1 = ids.indexOf(o1.getId());
int io2 = ids.indexOf(o2.getId());
if(io1 != -1){
io1 = users.size() - io1;
}
if(io2 != -1){
io2 = users.size() - io2;
}
return io2-io1;
});
}边栏推荐
- 高级计网笔记(七)
- Paper reading (56):muti features predction of protein translational modification sites (task)
- Leetcode: hash table 04 (sum of two numbers)
- 3000帧动画图解MySQL为什么需要binlog、redo log和undo log
- Dive into deep learning - 1. Introduction
- leetcode刷题:哈希表03 (快乐数)
- How to make good use of daily time to review efficiently?
- 剑指 Offer II 092. 翻转字符 / 剑指 Offer II 093. 最长斐波那契数列
- Why create a public OKR?
- Latex compiled successfully but could not be output to PDF
猜你喜欢

Improving efficiency or increasing costs, how should developers understand pair programming?

Torch learning (I): environment configuration

Paper reading (48):a Library of optimization algorithms for organizational design

【Qt】第三、四章:窗口部件、布局管理

Imeta | Nannong shenqirong team released microbial network analysis and visualization R package ggclusternet

Counter attack and defense (1): counter sample generation in image domain
![[Huazhong University of science and technology] information sharing for the first and second examinations of postgraduate entrance examination](/img/ec/884e656a921e20a5679a2960c9ac4d.jpg)
[Huazhong University of science and technology] information sharing for the first and second examinations of postgraduate entrance examination

leetcode刷题:哈希表06 (赎金信)

渗透测试基础,初识渗透测试

Thesis reading (53):universal advantageous perturbations
随机推荐
QML类型:Loader
Leetcode question brushing: hash table 05 (adding four numbers II)
The battlefield of live broadcast e-commerce is not in the live broadcast room
【 Huazhong University of Science and technology】 Data Sharing for retest of the initial Examination
uniapp项目中防止用户重复提交
Dive into deep learning - 1. Introduction
科技互动沙盘是凭借什么收获人气的
Leetcode question brushing: hash table 01 (valid Letter ectopic words)
CV-背景-简介
Description of all shortcut keys in win11 system
MySQL -- classic interview questions
高级计网笔记(九)
Shell脚本编写
嵌入式开发基础之任务管理(线程管理)
Wechat applet reports an error [app.json file content error] app json: app. JSON not found
可编程交换机上的近似公平排队阅读笔记
NetSeer:可编程数据平面的流事件遥测笔记
Leetcode: hash table 06 (ransom letter)
CV-全连接神经网络
Paper reading (50):a novel matrix game with payoffs of maximal belt structure